[banshee] DapService: avoid freezing Banshee when unmapping device (bgo#723040)



commit b0e172f01374f807bf396b6a289e51f56f851e31
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Wed Feb 5 00:05:32 2014 +0100

    DapService: avoid freezing Banshee when unmapping device (bgo#723040)
    
    It could happen that a Map event generated a process that
    could take a while to detect the device, which would hold the
    DapService.sync lock, which is also used by the Unmap events,
    and the latter events run in the main thread, so this could
    mean that banshee gets frozen for a time as long as it takes
    to detect/connect to the device.
    
    To fix this we simply need to spawn a thread for the Unmap
    operation. This thread will later call ThreadAssist API again
    to come back to the main thread when the UI needs to be
    changed, but that's ok. On top of that, the Dispose() was
    actually being called outside this ThreadAssist.ProxyToMain()
    call, so it was generating bad gui-thread-check traces, so
    it's a good time to fix this as well.

 src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs b/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
index ce01167..78874f4 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
@@ -254,6 +254,11 @@ namespace Banshee.Dap
 
         internal void UnmapDevice (string uuid)
         {
+            ThreadAssist.SpawnFromMain (() => Unmap (uuid));
+        }
+
+        private void Unmap (string uuid)
+        {
             DapSource source = null;
             lock (sync) {
                 if (sources.ContainsKey (uuid)) {
@@ -264,14 +269,14 @@ namespace Banshee.Dap
             }
 
             if (source != null) {
-                try {
-                    source.Dispose ();
-                    ThreadAssist.ProxyToMain (delegate {
+                ThreadAssist.ProxyToMain (delegate {
+                    try {
+                        source.Dispose ();
                         ServiceManager.SourceManager.RemoveSource (source);
-                    });
-                } catch (Exception e) {
-                    Log.Exception (e);
-                }
+                    } catch (Exception e) {
+                        Log.Exception (e);
+                    }
+                });
             }
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]