darwin: use clock_gettime in macOS 10.12
PR-URL: https://github.com/libuv/libuv/pull/1073 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
This commit is contained in:
parent
8658ef06c2
commit
f8d4805087
@ -34,8 +34,12 @@
|
||||
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h> /* 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user