]> git.sesse.net Git - vlc/commitdiff
libvlc: cond_wait can wake up without being signaled.
authorPierre d'Herbemont <pdherbemont@free.fr>
Fri, 5 Jun 2009 05:21:30 +0000 (22:21 -0700)
committerPierre d'Herbemont <pdherbemont@free.fr>
Fri, 5 Jun 2009 05:34:25 +0000 (22:34 -0700)
Pointed by Laurent.

src/control/event_async.c

index 43db2138b0ed6851b8903bc73bd905f68b699ce3..147e87bc2eee4901baf33970a98c32e2ecb09ab9 100644 (file)
@@ -61,6 +61,11 @@ static inline bool is_queue_initialized(libvlc_event_manager_t * p_em)
     return queue(p_em) != NULL;
 }
 
+static inline bool current_thread_is_asynch_thread(libvlc_event_manager_t * p_em)
+{
+    return vlc_threadvar_get(queue(p_em)->is_asynch_dispatch_thread_var);
+}
+
 /* Lock must be held */
 static void push(libvlc_event_manager_t * p_em, libvlc_event_listener_t * listener, libvlc_event_t * event)
 {
@@ -209,13 +214,11 @@ libvlc_event_async_ensure_listener_removal(libvlc_event_manager_t * p_em, libvlc
     queue_lock(p_em);
     pop_listener(p_em, listener);
     
-    bool is_asynch_dispatch_thread = vlc_threadvar_get(queue(p_em)->is_asynch_dispatch_thread_var);
-
     // Wait for the asynch_loop to have processed all events.
-    if(!queue(p_em)->is_idle && !is_asynch_dispatch_thread)
+    if(!current_thread_is_asynch_thread(p_em))
     {
-        vlc_cond_wait(&queue(p_em)->signal_idle, &queue(p_em)->lock);
-        assert(queue(p_em)->is_idle);
+        while(!queue(p_em)->is_idle)
+            vlc_cond_wait(&queue(p_em)->signal_idle, &queue(p_em)->lock);
     }
     queue_unlock(p_em);
 }