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-linux.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-linux.c')
-rw-r--r-- | osdep/timer-linux.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c index 63f7ad913f..314aa47b27 100644 --- a/osdep/timer-linux.c +++ b/osdep/timer-linux.c @@ -26,35 +26,27 @@ #include "config.h" #include "timer.h" -int usec_sleep(int usec_delay) +void mp_sleep_us(int64_t us) { + if (us < 0) + return; #ifdef HAVE_NANOSLEEP struct timespec ts; - ts.tv_sec = usec_delay / 1000000; - ts.tv_nsec = (usec_delay % 1000000) * 1000; - return nanosleep(&ts, NULL); + ts.tv_sec = us / 1000000; + ts.tv_nsec = (us % 1000000) * 1000; + nanosleep(&ts, NULL); #else - return usleep(usec_delay); + usleep(us); #endif } -// Returns current time in microseconds -unsigned int GetTimer(void) +uint64_t mp_raw_time_us(void) { - struct timeval tv; - gettimeofday(&tv,NULL); - return tv.tv_sec * 1000000 + tv.tv_usec; + struct timeval tv; + gettimeofday(&tv,NULL); + return tv.tv_sec * 1000000LL + tv.tv_usec; } -// Returns current time in milliseconds -unsigned int GetTimerMS(void) -{ - struct timeval tv; - gettimeofday(&tv,NULL); - return tv.tv_sec * 1000 + tv.tv_usec / 1000; -} - -// Initialize timer, must be called at least once at start -void InitTimer(void) +void mp_raw_time_init(void) { } |