From 8b12ae73e8322f6ed8c70f45cb24a20050bbe92f Mon Sep 17 00:00:00 2001 From: Baruch Even Date: Thu, 4 Sep 2014 22:11:45 +0300 Subject: [PATCH] Use CLOCK_MONOTONIC instead of CLOCK_REALTIME This prevents problems when the clock is jumping around which can happen when NTP starts or in a misconfigured environment with multiple NTP servers that are out of sync. --- libcurvecpr/lib/util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libcurvecpr/lib/util.c b/libcurvecpr/lib/util.c index 08fc8cc..baf0f58 100644 --- a/libcurvecpr/lib/util.c +++ b/libcurvecpr/lib/util.c @@ -61,7 +61,12 @@ long long curvecpr_util_nanoseconds (void) if (clock_get_time(cclock, &t) != KERN_SUCCESS) return -1; -#else +#elif defined(CLOCK_MONOTONIC) + struct timespec t; + + if (clock_gettime(CLOCK_MONOTONIC, &t) != 0) + return -1; +#elif defined(CLOCK_REALTIME) struct timespec t; if (clock_gettime(CLOCK_REALTIME, &t) != 0)