diff options
Diffstat (limited to 'os/utils.c')
-rw-r--r-- | os/utils.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/os/utils.c b/os/utils.c index afdff0c5a..18fd91151 100644 --- a/os/utils.c +++ b/os/utils.c @@ -427,7 +427,21 @@ GetTimeInMillis(void) #ifdef MONOTONIC_CLOCK struct timespec tp; - if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) + static clockid_t clockid; + if (!clockid) { +#ifdef CLOCK_MONOTONIC_COARSE + if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 && + (tp.tv_nsec / 1000) <= 1000 && + clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0) + clockid = CLOCK_MONOTONIC_COARSE; + else +#endif + if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) + clockid = CLOCK_MONOTONIC; + else + clockid = ~0L; + } + if (clockid != ~0L && clock_gettime(clockid, &tp) == 0) return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L); #endif |