From c6166ff448432dc74c300933e5c93838d06c420a Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 6 Feb 2014 21:04:24 +0100 Subject: timer: init only once This avoids trouble if another mpv instance is initialized in the same process. Since timeBeginPeriod/timeEndPeriod are hereby not easily matched anymore, use an atexit() handler to call timeEndPeriod, so that we can be sure these calls are matched, even if we allow multiple initializations later when introducing the client API. --- osdep/timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'osdep/timer.c') diff --git a/osdep/timer.c b/osdep/timer.c index d8dd49b9f7..f2c64959ab 100644 --- a/osdep/timer.c +++ b/osdep/timer.c @@ -16,12 +16,14 @@ */ #include +#include #include "timer.h" static uint64_t raw_time_offset; +pthread_once_t timer_init_once = PTHREAD_ONCE_INIT; -void mp_time_init(void) +static void do_timer_init(void) { mp_raw_time_init(); srand(mp_raw_time_us()); @@ -32,6 +34,11 @@ void mp_time_init(void) raw_time_offset -= 10000000; } +void mp_time_init(void) +{ + pthread_once(&timer_init_once, do_timer_init); +} + int64_t mp_time_us(void) { return mp_raw_time_us() - raw_time_offset; -- cgit v1.2.3