[banshee] Mtp: avoid aborting thread while using libmtp (bgo#724730)



commit 8997813470529ccd2b2db80f1da8a2d1e044aaab
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Wed Feb 19 17:09:51 2014 +0100

    Mtp: avoid aborting thread while using libmtp (bgo#724730)
    
    While the change in 37cb8a36f0a5884936fde0c84e7a9da87d19794a
    was desirable to avoid misleading exceptions being thrown, it
    exposed a situation that could not happen before that change:
    the load thread being aborted in the middle of a libmtp access
    (mtp_device field usage), because before that change, the load
    thread would just be aborted when trying to access a null lock
    (which means, the thread could only aborted outside when
    running outside the mtp_device lock, which was more desirable).
    
    In order to avoid this situation, we can make the DapSource
    parent class hook on its child's lock by using a virtual
    property that the child will map to its internal lock. This
    way, we will only kill the load_thread when we have the lock
    held (so no other thread is using mtp_device field).

 .../Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs   |   10 ++++++----
 src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs       |   17 +++++++++++------
 2 files changed, 17 insertions(+), 10 deletions(-)
---
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 9e70cb8..1d00c7a 100644
--- a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
+++ b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
@@ -32,14 +32,11 @@ using System.Threading;
 using Mono.Unix;
 
 using Hyena;
-using Hyena.Collections;
 using Mtp;
 using MTP = Mtp;
 
-using Banshee.Base;
 using Banshee.Dap;
 using Banshee.ServiceStack;
-using Banshee.Library;
 using Banshee.Sources;
 using Banshee.Playlist;
 using Banshee.Configuration;
@@ -51,7 +48,12 @@ namespace Banshee.Dap.Mtp
 {
     public class MtpSource : DapSource
     {
-               private MtpDevice mtp_device;
+
+        protected override object InternalLock {
+            get { return mtp_device; }
+        }
+        private MtpDevice mtp_device;
+
         //private bool supports_jpegs = false;
         private Dictionary<long, Track> track_map;
 
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs b/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
index e3b1b8d..2f1cabc 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
@@ -28,7 +28,6 @@
 //
 
 using System;
-using System.Linq;
 using System.IO;
 using System.Collections.Generic;
 using System.Threading;
@@ -37,7 +36,6 @@ using Mono.Unix;
 using Hyena;
 using Hyena.Data.Sqlite;
 
-using Banshee.Base;
 using Banshee.ServiceStack;
 using Banshee.Sources;
 using Banshee.Collection;
@@ -96,13 +94,20 @@ namespace Banshee.Dap
             TypeUniqueId = device.Serial;
         }
 
+        private object internal_lock = new object ();
+        protected virtual object InternalLock {
+            get { return internal_lock; }
+        }
+
         public override void Dispose ()
         {
-            if (load_thread != null) {
-                if (load_thread.IsAlive) {
-                    load_thread.Abort ();
+            lock (InternalLock) {
+                if (load_thread != null) {
+                    if (load_thread.IsAlive) {
+                        load_thread.Abort ();
+                    }
+                    load_thread = null;
                 }
-                load_thread = null;
             }
 
             Flush ();


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