Fall back to CLOCK_REALTIME if CLOCK_MONOTONIC not usable.

Sounds like this may be necessary on some older systems.
This commit is contained in:
Martin Ling 2018-09-23 18:03:32 +01:00
parent 192e77492a
commit 7fb9a7b0a7
1 changed files with 2 additions and 1 deletions

View File

@ -61,7 +61,8 @@ static void get_time(struct timeval *time)
{ {
#ifdef HAVE_CLOCK_GETTIME #ifdef HAVE_CLOCK_GETTIME
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
clock_gettime(CLOCK_REALTIME, &ts);
time->tv_sec = ts.tv_sec; time->tv_sec = ts.tv_sec;
time->tv_usec = ts.tv_nsec / 1000; time->tv_usec = ts.tv_nsec / 1000;
#elif defined(__APPLE__) #elif defined(__APPLE__)