]> git.sesse.net Git - vlc/commitdiff
Android: do not use semaphores from vlc_testcancel()
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 14 Nov 2012 16:26:54 +0000 (18:26 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 14 Nov 2012 16:26:54 +0000 (18:26 +0200)
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.

src/android/thread.c

index 7d15b2d7d7b6658fd678d826f09bdaed9862c8d5..3ef87cfa29daf74adb17d767b389d00daa0a33a4 100644 (file)
@@ -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);
 }