[vlc-commits] commit: Timer: do not run concurrently ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Wed Oct 13 18:23:39 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct 13 19:07:40 2010 +0300| [13f0c6d0fc7fb56d0fc69b072db95089902ed9b4] | committer: Rémi Denis-Courmont 

Timer: do not run concurrently

This is useless and awkward.

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

 src/misc/pthread.c |   39 +++++----------------------------------
 1 files changed, 5 insertions(+), 34 deletions(-)

diff --git a/src/misc/pthread.c b/src/misc/pthread.c
index 3d07092..ae00267 100644
--- a/src/misc/pthread.c
+++ b/src/misc/pthread.c
@@ -801,7 +801,6 @@ struct vlc_timer
 {
     vlc_thread_t thread;
     vlc_mutex_t  lock;
-    vlc_cond_t   wait;
     void       (*func) (void *);
     void        *data;
     mtime_t      value, interval;
@@ -809,20 +808,6 @@ struct vlc_timer
     vlc_atomic_t overruns;
 };
 
-static void *vlc_timer_do (void *data)
-{
-    struct vlc_timer *timer = data;
-
-    timer->func (timer->data);
-
-    vlc_mutex_lock (&timer->lock);
-    assert (timer->users > 0);
-    if (--timer->users == 0)
-        vlc_cond_signal (&timer->wait);
-    vlc_mutex_unlock (&timer->lock);
-    return NULL;
-}
-
 static void *vlc_timer_thread (void *data)
 {
     struct vlc_timer *timer = data;
@@ -835,19 +820,11 @@ static void *vlc_timer_thread (void *data)
 
     for (;;)
     {
-         vlc_thread_t th;
-
          mwait (value);
 
-         vlc_mutex_lock (&timer->lock);
-         if (vlc_clone (&th, vlc_timer_do, timer, VLC_THREAD_PRIORITY_INPUT))
-             vlc_atomic_inc(&timer->overruns);
-         else
-         {
-             vlc_detach (th);
-             timer->users++;
-         }
-         vlc_mutex_unlock (&timer->lock);
+         int canc = vlc_savecancel ();
+         timer->func (timer->data);
+         vlc_restorecancel (canc);
 
          if (interval == 0)
              return NULL;
@@ -870,7 +847,8 @@ static void *vlc_timer_thread (void *data)
 /**
  * Initializes an asynchronous timer.
  * @warning Asynchronous timers are processed from an unspecified thread.
- * Also, multiple occurences of an interval timer can run concurrently.
+ * Multiple occurences of a single interval timer are serialized; they cannot
+ * run concurrently.
  *
  * @param id pointer to timer to be initialized
  * @param func function that the timer will call
@@ -884,7 +862,6 @@ int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data)
     if (unlikely(timer == NULL))
         return ENOMEM;
     vlc_mutex_init (&timer->lock);
-    vlc_cond_init (&timer->wait);
     assert (func);
     timer->func = func;
     timer->data = data;
@@ -908,12 +885,6 @@ int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data)
 void vlc_timer_destroy (vlc_timer_t timer)
 {
     vlc_timer_schedule (timer, false, 0, 0);
-    vlc_mutex_lock (&timer->lock);
-    while (timer->users != 0)
-        vlc_cond_wait (&timer->wait, &timer->lock);
-    vlc_mutex_unlock (&timer->lock);
-
-    vlc_cond_destroy (&timer->wait);
     vlc_mutex_destroy (&timer->lock);
     free (timer);
 }



More information about the vlc-commits mailing list