From c0a61c3bb323724532fa9c1ac190afb36e4ae264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Sun, 14 Apr 2024 11:34:50 +0200 Subject: [PATCH] darwin: simplify uv_hrtime mach_continuous_time is available since macOS 10.12, but our minimum version is 11, so no need for a workaround. Also, prefer that to `clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW)` which the documentation suggests (https://developer.apple.com/documentation/driverkit/3438077-mach_continuous_time) since the latter calls mach_timebase_info every time, unnecessarify: https://github.com/apple-open-source/macos/blob/49dcc07a40d19fa97384033a8398dae5d00d11a1/Libc/gen/clock_gettime.c#L107 --- src/unix/darwin.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/unix/darwin.c b/src/unix/darwin.c index 5e764a65..009efbef 100644 --- a/src/unix/darwin.c +++ b/src/unix/darwin.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include /* _NSGetExecutablePath */ @@ -34,7 +33,6 @@ #include /* sysconf */ static uv_once_t once = UV_ONCE_INIT; -static uint64_t (*time_func)(void); static mach_timebase_info_data_t timebase; @@ -56,16 +54,12 @@ void uv__platform_loop_delete(uv_loop_t* loop) { static void uv__hrtime_init_once(void) { if (KERN_SUCCESS != mach_timebase_info(&timebase)) abort(); - - time_func = (uint64_t (*)(void)) dlsym(RTLD_DEFAULT, "mach_continuous_time"); - if (time_func == NULL) - time_func = mach_absolute_time; } uint64_t uv__hrtime(uv_clocktype_t type) { uv_once(&once, uv__hrtime_init_once); - return time_func() * timebase.numer / timebase.denom; + return mach_continuous_time() * timebase.numer / timebase.denom; }