timespec_get compat

macOS 10.11 which we still use for backward-compatible mac builds
doesn't have timespec_get function.
This commit is contained in:
Martin Pulec
2022-03-22 09:24:25 +01:00
parent 273a1082d2
commit 17fa2dba42
2 changed files with 7 additions and 0 deletions

View File

@@ -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

View File

@@ -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