From 04a1060f4511dca6b1d8d28f671cb2d8923e04df Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 31 Oct 2019 13:43:56 +0000 Subject: [PATCH] [Minor] Add better support for non-Linux systems --- contrib/libev/ev.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/contrib/libev/ev.c b/contrib/libev/ev.c index c69504731..38438e745 100644 --- a/contrib/libev/ev.c +++ b/contrib/libev/ev.c @@ -2893,15 +2893,22 @@ loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT if (!clock_gettime (CLOCK_MONOTONIC, &ts)) { have_monotonic = 1; monotinic_clock_id = CLOCK_MONOTONIC; +#define CHECK_CLOCK_SOURCE(id) do { \ + if (!clock_gettime ((id), &ts) && \ + !clock_getres ((id), &ts)) { \ + if (ts.tv_sec == 0 && ts.tv_nsec < 10ULL * 1000000) { \ + monotinic_clock_id = (id); \ + } \ + } \ +} while(0) #ifdef CLOCK_MONOTONIC_COARSE - if (!clock_gettime (CLOCK_MONOTONIC_COARSE, &ts) && - !clock_getres (CLOCK_MONOTONIC_COARSE, &ts)) { - /* Check if we have at least 10ms resolution */ - if (ts.tv_sec == 0 && ts.tv_nsec < 10ULL * 1000000) { - monotinic_clock_id = CLOCK_MONOTONIC_COARSE; - } - } + CHECK_CLOCK_SOURCE(CLOCK_MONOTONIC_COARSE); +#elif defined(CLOCK_MONOTONIC_FAST) /* BSD stuff */ + CHECK_CLOCK_SOURCE(CLOCK_MONOTONIC_FAST); +#elif defined(CLOCK_MONOTONIC_RAW_APPROX) /* OSX stuff */ + CHECK_CLOCK_SOURCE(CLOCK_MONOTONIC_RAW_APPROX); #endif +#undef CHECK_CLOCK_SOURCE } } #endif -- 2.39.5