[banshee] Dap.{Mtp|AppleDevice}: Decrease chances of deadlock
- From: AndrÃs Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] Dap.{Mtp|AppleDevice}: Decrease chances of deadlock
- Date: Tue, 1 May 2012 19:00:06 +0000 (UTC)
commit 29e909b2addb6e1c60f98d5b6518ea0f5308dda4
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 450345c..849c546 100644
--- a/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
+++ b/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
@@ -474,8 +474,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]