Commit 6f2119ef authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Timer: make the overrun counter atomic

parent d25fd8d7
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#endif #endif
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_atomic.h>
#include "libvlc.h" #include "libvlc.h"
#include <stdarg.h> #include <stdarg.h>
...@@ -805,7 +806,7 @@ struct vlc_timer ...@@ -805,7 +806,7 @@ struct vlc_timer
void *data; void *data;
mtime_t value, interval; mtime_t value, interval;
unsigned users; unsigned users;
unsigned overruns; vlc_atomic_t overruns;
}; };
static void *vlc_timer_do (void *data) static void *vlc_timer_do (void *data)
...@@ -840,7 +841,7 @@ static void *vlc_timer_thread (void *data) ...@@ -840,7 +841,7 @@ static void *vlc_timer_thread (void *data)
vlc_mutex_lock (&timer->lock); vlc_mutex_lock (&timer->lock);
if (vlc_clone (&th, vlc_timer_do, timer, VLC_THREAD_PRIORITY_INPUT)) if (vlc_clone (&th, vlc_timer_do, timer, VLC_THREAD_PRIORITY_INPUT))
timer->overruns++; vlc_atomic_inc(&timer->overruns);
else else
{ {
vlc_detach (th); vlc_detach (th);
...@@ -859,9 +860,7 @@ static void *vlc_timer_thread (void *data) ...@@ -859,9 +860,7 @@ static void *vlc_timer_thread (void *data)
if (misses > 1) if (misses > 1)
{ {
misses--; misses--;
vlc_mutex_lock (&timer->lock); vlc_atomic_add (&timer->overruns, misses);
timer->overruns += misses;
vlc_mutex_unlock (&timer->lock);
value += misses * interval; value += misses * interval;
} }
value += interval; value += interval;
...@@ -892,7 +891,7 @@ int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data) ...@@ -892,7 +891,7 @@ int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data)
timer->value = 0; timer->value = 0;
timer->interval = 0; timer->interval = 0;
timer->users = 0; timer->users = 0;
timer->overruns = 0; vlc_atomic_set(&timer->overruns, 0);
*id = timer; *id = timer;
return 0; return 0;
} }
...@@ -970,11 +969,5 @@ void vlc_timer_schedule (vlc_timer_t timer, bool absolute, ...@@ -970,11 +969,5 @@ void vlc_timer_schedule (vlc_timer_t timer, bool absolute,
*/ */
unsigned vlc_timer_getoverrun (vlc_timer_t timer) unsigned vlc_timer_getoverrun (vlc_timer_t timer)
{ {
unsigned ret; return vlc_atomic_swap (&timer->overruns, 0);
vlc_mutex_lock (&timer->lock);
ret = timer->overruns;
timer->overruns = 0;
vlc_mutex_unlock (&timer->lock);
return ret;
} }
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