From dea75d100d20924acc0c9a5091fe2eaddc4b9b68 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Thu, 13 Oct 2016 14:10:34 +0200 Subject: [PATCH] Readded compatibility with macOS 10.11 and earlier CLOCK_REALTIME is available only since macOS 10.12 and was used just in the platform_time.c file (under macOS). --- src/compat/platform_time.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/compat/platform_time.c b/src/compat/platform_time.c index f9365d7ce..a0a2cadef 100644 --- a/src/compat/platform_time.c +++ b/src/compat/platform_time.c @@ -52,6 +52,11 @@ #include #include "compat/platform_time.h" +#ifdef __MACH__ +#include +#include +#endif + uint64_t time_since_epoch_in_ms() { #ifdef WIN32 @@ -64,11 +69,19 @@ uint64_t time_since_epoch_in_ms() i.HighPart = f.dwHighDateTime; return (i.QuadPart - 1164444736000000000ll) / 10000; -#else +#elif defined CLOCK_REALTIME struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +#else + 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 * 1000ll + mts.tv_nsec / 1000000ll; #endif }