From 071822d28137c099dd37ad5eb2fe00ec0aae3fbc Mon Sep 17 00:00:00 2001 From: def Date: Tue, 28 Jun 2016 23:30:35 +0200 Subject: [PATCH] Use clock_gettime(CLOCK_MONOTONIC) instead of gettimeofday(). Seems to work fine. (The initial bugs I had with this were caused by my system's clock being wrong) --- src/base/system.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index c9aab57ba..e91aa139e 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -670,15 +670,15 @@ void set_new_tick() int64 time_get() { static int64 last = 0; - if(!new_tick) + if(new_tick == 0) return last; if(new_tick != -1) new_tick = 0; #if defined(CONF_FAMILY_UNIX) - struct timeval val; - gettimeofday(&val, NULL); - last = (int64)val.tv_sec*(int64)1000000+(int64)val.tv_usec; + struct timespec spec; + clock_gettime(CLOCK_MONOTONIC, &spec); + last = (int64)spec.tv_sec*(int64)1000000+(int64)spec.tv_nsec/1000; return last; #elif defined(CONF_FAMILY_WINDOWS) {