diff options
author | wm4 <wm4@nowhere> | 2013-05-17 19:54:37 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-05-26 16:44:20 +0200 |
commit | 81439c5f35e604174408a2aaf4e4dec11b81ac39 (patch) | |
tree | abd67642f487850c7f16666cc5f456d8f7ca347f /osdep/timer-win2.c | |
parent | 25d66f526ebae36a6c044652e5006450dd5a30df (diff) | |
download | mpv-81439c5f35e604174408a2aaf4e4dec11b81ac39.tar.bz2 mpv-81439c5f35e604174408a2aaf4e4dec11b81ac39.tar.xz |
timer: refactor, add 64 bit timer function
Make OS specific timer code export a mp_raw_time_us() function, and
add generic implementations of GetTimer()/GetTimerMS() using this
function. New mpv code is supposed to call mp_time_us() in situations
where precision is absolutely needed, or mp_time_s() otherwise.
Make it so that mp_time_us() will return a value near program start.
We don't set it to 0 though to avoid confusion with relative vs.
absolute time. Instead, pick an arbitrary offset.
Move the test program in timer-darwin.c to timer.c, and modify it to
work with the generic timer functions.
Diffstat (limited to 'osdep/timer-win2.c')
-rw-r--r-- | osdep/timer-win2.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/osdep/timer-win2.c b/osdep/timer-win2.c index 88a047410d..99980d76bc 100644 --- a/osdep/timer-win2.c +++ b/osdep/timer-win2.c @@ -22,27 +22,25 @@ #include <mmsystem.h> #include "timer.h" -// Returns current time in microseconds -unsigned int GetTimer(void) +void mp_sleep_us(int64_t us) { - return timeGetTime() * 1000; + if (us < 0) + return; + // Sleep(0) won't sleep for one clocktick as the unix usleep + // instead it will only make the thread ready + // it may take some time until it actually starts to run again + if (us < 1000) + us = 1000; + Sleep(us / 1000); } -// Returns current time in milliseconds -unsigned int GetTimerMS(void) +uint64_t mp_raw_time_us(void) { - return timeGetTime() ; + return timeGetTime() * 1000; } -int usec_sleep(int usec_delay){ - // Sleep(0) won't sleep for one clocktick as the unix usleep - // instead it will only make the thread ready - // it may take some time until it actually starts to run again - if(usec_delay<1000)usec_delay=1000; - Sleep( usec_delay/1000); - return 0; -} - -void InitTimer(void) +void mp_raw_time_init(void) { + // request 1ms timer resolution + timeBeginPeriod(1); } |