X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fw32thread.c;h=24f991e04db2796be491a3b7bc59565521c7a3a1;hb=abe9af559fb6df6931831e5ca757afb056669f7c;hp=7ed00af1352deaa0d32598c62bb64a00a2bea27f;hpb=50c84f608170941c787d6d74d80799ef588feca3;p=vlc diff --git a/src/misc/w32thread.c b/src/misc/w32thread.c index 7ed00af135..24f991e04d 100644 --- a/src/misc/w32thread.c +++ b/src/misc/w32thread.c @@ -53,7 +53,7 @@ typedef struct vlc_cancel_t #ifndef UNDER_CE # define VLC_CANCEL_INIT { NULL, true, false } #else -# define VLC_CANCEL_INIT { NULL, NULL; true, false } +# define VLC_CANCEL_INIT { NULL, NULL, true, false } #endif #ifdef UNDER_CE @@ -164,14 +164,12 @@ void vlc_mutex_init( vlc_mutex_t *p_mutex ) * no defined behavior in case of recursive locking. */ InitializeCriticalSection (&p_mutex->mutex); p_mutex->initialized = 1; - return 0; } void vlc_mutex_init_recursive( vlc_mutex_t *p_mutex ) { InitializeCriticalSection( &p_mutex->mutex ); p_mutex->initialized = 1; - return 0; } @@ -512,3 +510,62 @@ void vlc_control_cancel (int cmd, ...) } va_end (ap); } + + +/*** Timers ***/ +static void CALLBACK vlc_timer_do (void *val, BOOLEAN timeout) +{ + vlc_timer_t *id = val; + + assert (timeout); + if (TryEnterCriticalSection (&id->serializer)) + { + id->overrun = InterlockedExchange (&id->counter, 0); + id->func (id->data); + LeaveCriticalSection (&id->serializer); + } + else /* Overrun */ + InterlockedIncrement (&id->counter); +} + +int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data) +{ + id->func = func; + id->data = data; + id->overrun = 0; + id->handle = INVALID_HANDLE_VALUE; + InitializeCriticalSection (&id->serializer); + return 0; +} + +void vlc_timer_destroy (vlc_timer_t *id) +{ + if (id->handle != INVALID_HANDLE_VALUE) + DeleteTimerQueueTimer (NULL, id->handle, NULL); + DeleteCriticalSection (&id->serializer); +} + +void vlc_timer_schedule (vlc_timer_t *id, bool absolute, + mtime_t value, mtime_t interval) +{ + if (id->handle != INVALID_HANDLE_VALUE) + { + DeleteTimerQueueTimer (NULL, id->handle, NULL); + id->handle = INVALID_HANDLE_VALUE; + } + if (value == 0) + return; /* Disarm */ + + if (absolute) + value -= mdate (); + value = (value + 999) / 1000; + interval = (interval + 999) / 1000; + if (!CreateTimerQueueTimer (&id->handle, NULL, vlc_timer_do, id, value, + interval, WT_EXECUTEDEFAULT)) + abort (); +} + +unsigned vlc_timer_getoverrun (const vlc_timer_t *id) +{ + return id->overrun; +}