[vlc-commits] Android: do not use semaphores from vlc_testcancel()

Rémi Denis-Courmont git at videolan.org
Wed Nov 14 17:28:24 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Nov 14 18:26:54 2012 +0200| [2b51a84f34d6ad36e8f8b6998f1aaa29bd91c0b4] | committer: Rémi Denis-Courmont

Android: do not use semaphores from vlc_testcancel()

Taking any lock in vlc_testcancel() is prone to deadlock since it gets
called from vlc_cond_(timed)wait() with the mutex held.

Not using semaphores at all would probably be saner here though.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2b51a84f34d6ad36e8f8b6998f1aaa29bd91c0b4
---

 src/android/thread.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/android/thread.c b/src/android/thread.c
index 7d15b2d..3ef87cf 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -330,14 +330,23 @@ static void *detached_thread(void *data)
     return NULL;
 }
 
+static void finish_joinable_thread(void *data)
+{
+    vlc_thread_t th = data;
+
+    vlc_sem_post(&th->finished);
+}
+
 static void *joinable_thread(void *data)
 {
     vlc_thread_t th = data;
     void *ret;
 
+    vlc_cleanup_push(finish_joinable_thread, th);
     thread = th;
     ret = th->entry(th->data);
-    vlc_sem_post(&th->finished);
+    vlc_cleanup_run();
+
     return ret;
 }
 
@@ -461,7 +470,6 @@ void vlc_testcancel (void)
     if (!vlc_atomic_get(&thread->killed))
         return;
 
-    vlc_sem_post(&thread->finished);
     pthread_exit(NULL);
 }
 



More information about the vlc-commits mailing list