From 5c7723309302a0edca4f14be0fdd1835cd977949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 30 Jun 2016 09:38:51 +0000 Subject: [PATCH] Use clock_gettime() --- mud.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mud.c b/mud.c index 6ab4f7f..03902ba 100644 --- a/mud.c +++ b/mud.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -173,9 +174,17 @@ uint64_t mud_read48 (const unsigned char *src) static uint64_t mud_now (struct mud *mud) { - struct timeval now; - gettimeofday(&now, NULL); - return (now.tv_sec*MUD_ONE_SEC+now.tv_usec)&((UINT64_C(1)<<48)-1); + uint64_t now; +#if defined CLOCK_MONOTONIC + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + now = tv.tv_sec*MUD_ONE_SEC+tv.tv_nsec/MUD_ONE_MSEC; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + now = tv.tv_sec*MUD_ONE_SEC+tv.tv_usec; +#endif + return now&((UINT64_C(1)<<48)-1); } static