diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-10-28 21:17:28 +0200 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-11-08 04:32:10 +0000 |
commit | 0a6c179026654d8c672ce782feaa86a767cbbfe6 (patch) | |
tree | 37a5631e39bf881c929469828eddd2dae5fec0ee /osdep/timer-linux.c | |
parent | 468b9bede7f01dd27dff070c89ad21c765e51e00 (diff) | |
download | mpv-0a6c179026654d8c672ce782feaa86a767cbbfe6.tar.bz2 mpv-0a6c179026654d8c672ce782feaa86a767cbbfe6.tar.xz |
osdep/timer-linux: check clock availability on init
Diffstat (limited to 'osdep/timer-linux.c')
-rw-r--r-- | osdep/timer-linux.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c index bcae787645..559a496636 100644 --- a/osdep/timer-linux.c +++ b/osdep/timer-linux.c @@ -18,10 +18,15 @@ * License along with mpv. If not, see <http://www.gnu.org/licenses/>. */ +#include <errno.h> #include <stdlib.h> #include <time.h> + +#include "common/common.h" #include "timer.h" +static clockid_t clk_id; + void mp_sleep_ns(int64_t ns) { if (ns < 0) @@ -35,15 +40,25 @@ 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) - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &tp); -#endif - if (ret) - clock_gettime(CLOCK_MONOTONIC, &tp); + clock_gettime(clk_id, &tp); return MP_TIME_S_TO_NS(tp.tv_sec) + tp.tv_nsec; } void mp_raw_time_init(void) { + static const clockid_t clock_ids[] = { +#ifdef CLOCK_MONOTONIC_RAW + CLOCK_MONOTONIC_RAW, +#endif + CLOCK_MONOTONIC, + }; + + struct timespec tp; + for (int i = 0; i < MP_ARRAY_SIZE(clock_ids); ++i) { + clk_id = clock_ids[i]; + if (!clock_gettime(clk_id, &tp)) + return; + } + fputs("No clock source available!\n", stderr); + abort(); } |