diff --git a/src/ddsrt/src/time/darwin/time.c b/src/ddsrt/src/time/darwin/time.c index a8a35c4..71e2ccb 100644 --- a/src/ddsrt/src/time/darwin/time.c +++ b/src/ddsrt/src/time/darwin/time.c @@ -13,21 +13,29 @@ #include #include #include + +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 #include +#endif #include "dds/ddsrt/time.h" dds_time_t dds_time(void) { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 + return (int64_t) clock_gettime_nsec_np (CLOCK_REALTIME); +#else struct timeval tv; - (void)gettimeofday(&tv, NULL); - return ((tv.tv_sec * DDS_NSECS_IN_SEC) + (tv.tv_usec * DDS_NSECS_IN_USEC)); +#endif } dds_time_t ddsrt_time_monotonic(void) { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 + return (int64_t) clock_gettime_nsec_np (CLOCK_UPTIME_RAW); +#else static mach_timebase_info_data_t timeInfo; uint64_t mt; @@ -49,10 +57,15 @@ dds_time_t ddsrt_time_monotonic(void) } return (dds_time_t)(mt * timeInfo.numer / timeInfo.denom); +#endif } dds_time_t ddsrt_time_elapsed(void) { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 + return (int64_t) clock_gettime_nsec_np (CLOCK_MONOTONIC_RAW); +#else /* Elapsed time clock not (yet) supported on this platform. */ return ddsrt_time_monotonic(); +#endif }