From f8d4805087944cb8543d98109f5f83f4938eb4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 28 Sep 2016 18:07:32 +0100 Subject: [PATCH] darwin: use clock_gettime in macOS 10.12 PR-URL: https://github.com/libuv/libuv/pull/1073 Reviewed-By: Fedor Indutny Reviewed-By: Imran Iqbal --- src/unix/darwin.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/unix/darwin.c b/src/unix/darwin.c index cf95da21..b1ffbc37 100644 --- a/src/unix/darwin.c +++ b/src/unix/darwin.c @@ -34,8 +34,12 @@ #include /* _NSGetExecutablePath */ #include #include +#include #include /* sysconf */ +#undef NANOSEC +#define NANOSEC ((uint64_t) 1e9) + int uv__platform_loop_init(uv_loop_t* loop) { loop->cf_state = NULL; @@ -53,6 +57,11 @@ void uv__platform_loop_delete(uv_loop_t* loop) { uint64_t uv__hrtime(uv_clocktype_t type) { +#ifdef MAC_OS_X_VERSION_10_12 + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); +#else static mach_timebase_info_data_t info; if ((ACCESS_ONCE(uint32_t, info.numer) == 0 || @@ -61,6 +70,7 @@ uint64_t uv__hrtime(uv_clocktype_t type) { abort(); return mach_absolute_time() * info.numer / info.denom; +#endif }