From 17fa2dba4296ab0bfe110f93fb3fa911fdae83cb Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 22 Mar 2022 09:24:25 +0100 Subject: [PATCH] timespec_get compat macOS 10.11 which we still use for backward-compatible mac builds doesn't have timespec_get function. --- configure.ac | 1 + src/tv.h | 6 ++++++ 2 files changed, 7 insertions(+) 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