]> git.sesse.net Git - vlc/commitdiff
vlc_timer_gettime: fix corner-case dead lock
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 3 Aug 2009 16:35:37 +0000 (19:35 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 3 Aug 2009 16:35:37 +0000 (19:35 +0300)
If vlc_cancel() while the timer thread is between mwait() and
vlc_mutex_lock(), a dead lock would occur at vlc_join(). We need to
release the timer lock first.

src/misc/pthread.c

index 47ac47831d2a120bc01bb560bbcf8db85de8ed35..d31e38810b3007f22bbc0f89ec208f2e526a4edc 100644 (file)
@@ -812,11 +812,16 @@ void vlc_timer_destroy (vlc_timer_t timer)
 void vlc_timer_schedule (vlc_timer_t timer, bool absolute,
                          mtime_t value, mtime_t interval)
 {
+    static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+
+    vlc_mutex_lock (&lock);
     vlc_mutex_lock (&timer->lock);
     if (timer->value)
     {
+        vlc_mutex_unlock (&timer->lock);
         vlc_cancel (timer->thread);
         vlc_join (timer->thread, NULL);
+        vlc_mutex_lock (&timer->lock);
         timer->value = 0;
     }
     if ((value != 0)
@@ -827,6 +832,7 @@ void vlc_timer_schedule (vlc_timer_t timer, bool absolute,
         timer->interval = interval;
     }
     vlc_mutex_unlock (&timer->lock);
+    vlc_mutex_unlock (&lock);
 }
 
 /**