--- embedaddon/bmon/src/utils.c 2014/07/30 07:55:27 1.1.1.2 +++ embedaddon/bmon/src/utils.c 2019/10/21 14:58:35 1.1.1.3 @@ -27,6 +27,11 @@ #include #include +#ifdef __MACH__ +#include +#include +#endif + void *xcalloc(size_t n, size_t s) { void *d = calloc(n, s); @@ -112,18 +117,27 @@ int timestamp_is_negative(timestamp_t *ts) void update_timestamp(timestamp_t *dst) { - struct timeval tv; +#ifdef __MACH__ + clock_serv_t cclock; + mach_timespec_t tp; - gettimeofday(&tv, NULL); + host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); + clock_get_time(cclock, &tp); + mach_port_deallocate(mach_task_self(), cclock); +#else + struct timespec tp; - dst->tv_sec = tv.tv_sec; - dst->tv_usec = tv.tv_usec; + clock_gettime(CLOCK_MONOTONIC, &tp); +#endif + + dst->tv_sec = tp.tv_sec; + dst->tv_usec = tp.tv_nsec / 1000; } void copy_timestamp(timestamp_t *ts1, timestamp_t *ts2) { ts1->tv_sec = ts2->tv_sec; - ts2->tv_usec = ts2->tv_usec; + ts1->tv_usec = ts2->tv_usec; } float timestamp_diff(timestamp_t *t1, timestamp_t *t2)