diff --git a/configure.ac b/configure.ac index c3be80ee4..19753f5a7 100644 --- a/configure.ac +++ b/configure.ac @@ -322,6 +322,7 @@ fi AC_CHECK_FUNCS(usleep) AC_CHECK_FUNCS(strtok_r) +AC_CHECK_FUNCS(timespec_get) AC_CHECK_FUNCS(drand48) if test $ac_cv_func_drand48 = no diff --git a/src/tv.h b/src/tv.h index cc1f50053..33140bcd2 100644 --- a/src/tv.h +++ b/src/tv.h @@ -72,9 +72,15 @@ typedef long long time_ns_t; #define NS_IN_SEC 1000000000LL #define NS_IN_US (NS_IN_SEC/US_IN_SEC) static inline time_ns_t get_time_in_ns() { +#ifdef HAVE_TIMESPEC_GET struct timespec ts = { 0, 0 }; timespec_get(&ts, TIME_UTC); return ts.tv_sec * NS_IN_SEC + ts.tv_nsec; +#else + struct timeval tv = { 0, 0 }; + gettimeofday(&tv, NULL); + return tv.tv_sec * NS_IN_SEC + tv.tv_usec * NS_IN_US; +#endif } #ifdef __cplusplus