[banshee/stable-2.4] Dap.{Mtp|AppleDevice}: Decrease chances of deadlock



commit 51ce6a81c3db7ae7873482c763fc267242d95d9a
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Tue May 1 20:00:07 2012 +0100

    Dap.{Mtp|AppleDevice}: Decrease chances of deadlock
    
    Calling Monitor.Exit() outside of a finally block may increase
    the chances of a deadlock happening if an exception is throwing
    while the lock is held.

 .../Banshee.Dap.AppleDevice/AppleDeviceSource.cs   |    7 ++++-
 .../Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs   |   22 ++++++++++++-------
 2 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs b/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
index bbe3773..0070e70 100644
--- a/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
+++ b/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
@@ -464,8 +464,11 @@ namespace Banshee.Dap.AppleDevice
         public override void SyncPlaylists ()
         {
             if (!IsReadOnly && Monitor.TryEnter (sync_mutex)) {
-                PerformSync ();
-                Monitor.Exit (sync_mutex);
+                try {
+                    PerformSync ();
+                } finally {
+                    Monitor.Exit (sync_mutex);
+                }
             }
         }
 
diff --git a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
index c26025d..766f066 100644
--- a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
+++ b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
@@ -295,11 +295,14 @@ namespace Banshee.Dap.Mtp
         public override long BytesUsed {
             get {
                 if (Monitor.TryEnter (mtp_device)) {
-                    bytes_used = 0;
-                    foreach (DeviceStorage s in mtp_device.GetStorage ()) {
-                        bytes_used += (long) s.MaxCapacity - (long) s.FreeSpaceInBytes;
+                    try {
+                        bytes_used = 0;
+                        foreach (DeviceStorage s in mtp_device.GetStorage ()) {
+                            bytes_used += (long) s.MaxCapacity - (long) s.FreeSpaceInBytes;
+                        }
+                    } finally {
+                        Monitor.Exit (mtp_device);
                     }
-                    Monitor.Exit (mtp_device);
                 }
                 return bytes_used;
             }
@@ -309,11 +312,14 @@ namespace Banshee.Dap.Mtp
         public override long BytesCapacity {
             get {
                 if (Monitor.TryEnter (mtp_device)) {
-                    bytes_capacity = 0;
-                    foreach (DeviceStorage s in mtp_device.GetStorage ()) {
-                        bytes_capacity += (long) s.MaxCapacity;
+                    try {
+                        bytes_capacity = 0;
+                        foreach (DeviceStorage s in mtp_device.GetStorage ()) {
+                            bytes_capacity += (long) s.MaxCapacity;
+                        }
+                    } finally {
+                        Monitor.Exit (mtp_device);
                     }
-                    Monitor.Exit (mtp_device);
                 }
                 return bytes_capacity;
             }



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