diff options
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/timer-darwin.c | 5 | ||||
-rw-r--r-- | osdep/timer-linux.c | 8 | ||||
-rw-r--r-- | osdep/timer-win2.c | 12 | ||||
-rw-r--r-- | osdep/timer.h | 6 |
4 files changed, 15 insertions, 16 deletions
diff --git a/osdep/timer-darwin.c b/osdep/timer-darwin.c index a114d0d727..bb8a9b4324 100644 --- a/osdep/timer-darwin.c +++ b/osdep/timer-darwin.c @@ -28,10 +28,9 @@ static double timebase_ratio_ns; -void mp_sleep_us(int64_t us) +void mp_sleep_ns(int64_t ns) { - uint64_t deadline = us * 1e3 / timebase_ratio_ns + mach_absolute_time(); - + uint64_t deadline = ns / timebase_ratio_ns + mach_absolute_time(); mach_wait_until(deadline); } diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c index 0289233695..ff4b137cb2 100644 --- a/osdep/timer-linux.c +++ b/osdep/timer-linux.c @@ -22,13 +22,13 @@ #include <time.h> #include "timer.h" -void mp_sleep_us(int64_t us) +void mp_sleep_ns(int64_t ns) { - if (us < 0) + if (ns < 0) return; struct timespec ts; - ts.tv_sec = us / 1000000; - ts.tv_nsec = (us % 1000000) * 1000; + ts.tv_sec = ns / UINT64_C(1000000000); + ts.tv_nsec = ns % UINT64_C(1000000000); nanosleep(&ts, NULL); } diff --git a/osdep/timer-win2.c b/osdep/timer-win2.c index dd7a42f0d1..db4c39d7ef 100644 --- a/osdep/timer-win2.c +++ b/osdep/timer-win2.c @@ -52,17 +52,17 @@ void mp_end_hires_timers(int res_ms) #endif } -void mp_sleep_us(int64_t us) +void mp_sleep_ns(int64_t ns) { - if (us < 0) + if (ns < 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; - int hrt = mp_start_hires_timers(us / 1000); - Sleep(us / 1000); + if (ns < 1e6) + ns = 1e6; + int hrt = mp_start_hires_timers(ns / 1e6); + Sleep(ns / 1e6); mp_end_hires_timers(hrt); } diff --git a/osdep/timer.h b/osdep/timer.h index d76ad16129..b273cb405e 100644 --- a/osdep/timer.h +++ b/osdep/timer.h @@ -29,7 +29,7 @@ int64_t mp_time_us(void); // Return time in nanoseconds. Never wraps. Never returns 0 or negative values. int64_t mp_time_ns(void); -// Return time in seconds. Can have down to 1 microsecond resolution, but will +// Return time in seconds. Can have down to 1 nanosecond resolution, but will // be much worse when casted to float. double mp_time_sec(void); @@ -37,8 +37,8 @@ double mp_time_sec(void); void mp_raw_time_init(void); uint64_t mp_raw_time_ns(void); -// Sleep in microseconds. -void mp_sleep_us(int64_t us); +// Sleep in nanoseconds. +void mp_sleep_ns(int64_t ns); #ifdef _WIN32 // returns: timer resolution in ms if needed and started successfully, else 0 |