diff options
Diffstat (limited to 'lib/timeutils.c')
-rw-r--r-- | lib/timeutils.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/timeutils.c b/lib/timeutils.c index b811041e4..bd3d40248 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -340,3 +340,26 @@ int parse_timestamp(const char *t, usec_t *usec) return 0; } + + +int gettime_monotonic(struct timeval *tv) +{ +#ifdef CLOCK_MONOTONIC + /* Can slew only by ntp and adjtime */ + int ret; + struct timespec ts; + +# ifdef CLOCK_MONOTONIC_RAW + /* Linux specific, cant slew */ + if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) { +# else + if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) { +# endif + tv->tv_sec = ts.tv_sec; + tv->tv_usec = ts.tv_nsec / 1000; + } + return ret; +#else + return gettimeofday(tv, NULL); +#endif +} |