Commit 13f0c6d0 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Timer: do not run concurrently

This is useless and awkward.
parent 6f2119ef
...@@ -801,7 +801,6 @@ struct vlc_timer ...@@ -801,7 +801,6 @@ struct vlc_timer
{ {
vlc_thread_t thread; vlc_thread_t thread;
vlc_mutex_t lock; vlc_mutex_t lock;
vlc_cond_t wait;
void (*func) (void *); void (*func) (void *);
void *data; void *data;
mtime_t value, interval; mtime_t value, interval;
...@@ -809,20 +808,6 @@ struct vlc_timer ...@@ -809,20 +808,6 @@ struct vlc_timer
vlc_atomic_t overruns; 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) static void *vlc_timer_thread (void *data)
{ {
struct vlc_timer *timer = data; struct vlc_timer *timer = data;
...@@ -835,19 +820,11 @@ static void *vlc_timer_thread (void *data) ...@@ -835,19 +820,11 @@ static void *vlc_timer_thread (void *data)
for (;;) for (;;)
{ {
vlc_thread_t th;
mwait (value); mwait (value);
vlc_mutex_lock (&timer->lock); int canc = vlc_savecancel ();
if (vlc_clone (&th, vlc_timer_do, timer, VLC_THREAD_PRIORITY_INPUT)) timer->func (timer->data);
vlc_atomic_inc(&timer->overruns); vlc_restorecancel (canc);
else
{
vlc_detach (th);
timer->users++;
}
vlc_mutex_unlock (&timer->lock);
if (interval == 0) if (interval == 0)
return NULL; return NULL;
...@@ -870,7 +847,8 @@ static void *vlc_timer_thread (void *data) ...@@ -870,7 +847,8 @@ static void *vlc_timer_thread (void *data)
/** /**
* Initializes an asynchronous timer. * Initializes an asynchronous timer.
* @warning Asynchronous timers are processed from an unspecified thread. * @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 id pointer to timer to be initialized
* @param func function that the timer will call * @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) ...@@ -884,7 +862,6 @@ int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data)
if (unlikely(timer == NULL)) if (unlikely(timer == NULL))
return ENOMEM; return ENOMEM;
vlc_mutex_init (&timer->lock); vlc_mutex_init (&timer->lock);
vlc_cond_init (&timer->wait);
assert (func); assert (func);
timer->func = func; timer->func = func;
timer->data = data; timer->data = data;
...@@ -908,12 +885,6 @@ int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *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) void vlc_timer_destroy (vlc_timer_t timer)
{ {
vlc_timer_schedule (timer, false, 0, 0); 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); vlc_mutex_destroy (&timer->lock);
free (timer); free (timer);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment