diff options
author | Dudemanguy <random342@airmail.cc> | 2023-10-27 13:11:30 -0500 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-10-27 23:19:07 +0000 |
commit | 891efca9d79d4532f6bbe763d8f90ba837bbe0a4 (patch) | |
tree | 1f201db889b2ef051ed637c363bb02d2fa41aa78 /osdep/timer-linux.c | |
parent | bc3e850168b10fe37efb1d0364373dd848552abe (diff) | |
download | mpv-891efca9d79d4532f6bbe763d8f90ba837bbe0a4.tar.bz2 mpv-891efca9d79d4532f6bbe763d8f90ba837bbe0a4.tar.xz |
timer-linux: fallback to CLOCK_MONOTONIC instead of timespec_get
CLOCK_MONOTONIC_RAW is linux-specific (macOS later supported it but it
has its own timer code) and not neccessarily available everywhere like
on BSDs. It makes sense to prefer it because mpv does a lot of
measurements at small intervals (e.g. every frame) so theoretically it
should be more accurate. However if the OS doesn't have it, fallback to
CLOCK_MONOTONIC instead which is almost exactly the same and very widely
supported across unix-like systems. This clock is technically optional
according to POSIX, but any half-decent OS supports it anyway (sorry
Solaris users). As a benefit, we now know that the clock from mp_time is
always monotonic.
Diffstat (limited to 'osdep/timer-linux.c')
-rw-r--r-- | osdep/timer-linux.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c index 25bb70bcca..bcae787645 100644 --- a/osdep/timer-linux.c +++ b/osdep/timer-linux.c @@ -35,11 +35,12 @@ void mp_sleep_ns(int64_t ns) uint64_t mp_raw_time_ns(void) { struct timespec tp = {0}; + int ret = -1; #if defined(CLOCK_MONOTONIC_RAW) - clock_gettime(CLOCK_MONOTONIC_RAW, &tp); -#else - timespec_get(&tp, TIME_UTC); + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &tp); #endif + if (ret) + clock_gettime(CLOCK_MONOTONIC, &tp); return MP_TIME_S_TO_NS(tp.tv_sec) + tp.tv_nsec; } |