From b821c8e33c539afe687ee844181d40accf958c33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20K=C3=B6plinger?= Date: Tue, 14 Jun 2016 16:39:41 +0200 Subject: [PATCH] [utils] Work around CLOCK_MONOTONIC being defined on macOS 10.12 SDK despite targeting earlier releases Should fix https://bugzilla.xamarin.com/show_bug.cgi?id=41786 --- mono/utils/mono-time.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mono/utils/mono-time.c b/mono/utils/mono-time.c index 5cc82fccb55..06f9f217b88 100644 --- a/mono/utils/mono-time.c +++ b/mono/utils/mono-time.c @@ -142,7 +142,16 @@ gint64 mono_100ns_ticks (void) { struct timeval tv; -#ifdef CLOCK_MONOTONIC +#if defined(PLATFORM_MACOSX) + /* http://developer.apple.com/library/mac/#qa/qa1398/_index.html */ + static mach_timebase_info_data_t timebase; + guint64 now = mach_absolute_time (); + if (timebase.denom == 0) { + mach_timebase_info (&timebase); + timebase.denom *= 100; /* we return 100ns ticks */ + } + return now * timebase.numer / timebase.denom; +#elif defined(CLOCK_MONOTONIC) struct timespec tspec; static struct timespec tspec_freq = {0}; static int can_use_clock = 0; @@ -156,16 +165,6 @@ mono_100ns_ticks (void) return ((gint64)tspec.tv_sec * MTICKS_PER_SEC + tspec.tv_nsec / 100); } } - -#elif defined(PLATFORM_MACOSX) - /* http://developer.apple.com/library/mac/#qa/qa1398/_index.html */ - static mach_timebase_info_data_t timebase; - guint64 now = mach_absolute_time (); - if (timebase.denom == 0) { - mach_timebase_info (&timebase); - timebase.denom *= 100; /* we return 100ns ticks */ - } - return now * timebase.numer / timebase.denom; #endif if (gettimeofday (&tv, NULL) == 0) return ((gint64)tv.tv_sec * 1000000 + tv.tv_usec) * 10; -- 2.25.1