From b8e45926f66fd928bccf2b03377f20788f52774b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 26 Nov 2014 23:41:33 +0000 Subject: move to using POSIX monotonic clock if available --- src/time.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/time.c') diff --git a/src/time.c b/src/time.c index b29c2eb..582bc9d 100644 --- a/src/time.c +++ b/src/time.c @@ -14,19 +14,27 @@ #include #include +#include #include +#include #include "nsutils/time.h" /* exported interface documented in nsutils/time.h */ nsuerror nsu_getmonotonic_ms(uint64_t *current) { +#if (_POSIX_TIMERS > 0) && (defined _POSIX_MONOTONIC_CLOCK) + struct timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + *current = (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000); +#else +#warning "Using dodgy gettimeofday() fallback" /** \todo Implement this properly! */ struct timeval tv; gettimeofday(&tv, NULL); *current = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); - +#endif return NSUERROR_OK; } -- cgit v1.2.3