diff options
Diffstat (limited to 'Utilities/cmlibuv/src/unix/posix-hrtime.c')
-rw-r--r-- | Utilities/cmlibuv/src/unix/posix-hrtime.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Utilities/cmlibuv/src/unix/posix-hrtime.c b/Utilities/cmlibuv/src/unix/posix-hrtime.c index 323dfc2..a264250 100644 --- a/Utilities/cmlibuv/src/unix/posix-hrtime.c +++ b/Utilities/cmlibuv/src/unix/posix-hrtime.c @@ -22,6 +22,29 @@ #include "uv.h" #include "internal.h" +#if defined(__APPLE__) +/* Special case for CMake bootstrap: no clock_gettime on macOS < 10.12 */ + +#ifndef CMAKE_BOOTSTRAP +#error "This code path meant only for use during CMake bootstrap." +#endif + +#include <mach/mach.h> +#include <mach/mach_time.h> + +uint64_t uv__hrtime(uv_clocktype_t type) { + static mach_timebase_info_data_t info; + + if ((ACCESS_ONCE(uint32_t, info.numer) == 0 || + ACCESS_ONCE(uint32_t, info.denom) == 0) && + mach_timebase_info(&info) != KERN_SUCCESS) + abort(); + + return mach_absolute_time() * info.numer / info.denom; +} + +#else + #include <stdint.h> #include <time.h> @@ -33,3 +56,5 @@ uint64_t uv__hrtime(uv_clocktype_t type) { clock_gettime(CLOCK_MONOTONIC, &ts); return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } + +#endif |