From e91eb74f3e09db8f1f9d8b56d6fdcb0246f21a06 Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Wed, 19 Oct 2016 09:22:37 +0200 Subject: [PATCH] more accurate getTickCount for macOS --- common/timeDefs.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/common/timeDefs.h b/common/timeDefs.h index 48ad2234..847ad809 100644 --- a/common/timeDefs.h +++ b/common/timeDefs.h @@ -21,6 +21,10 @@ #include #include +#ifdef MACOS +#include +#include +#endif namespace chronos { @@ -49,9 +53,12 @@ namespace chronos inline static long getTickCount() { #ifdef MACOS - struct timeval now; - gettimeofday(&now, NULL); - return now.tv_sec*1000 + now.tv_usec / 1000; + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + return mts.tv_sec*1000 + mts.tv_nsec / 1000000; #else struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now);