Index: src/chrono.cpp =================================================================== --- src/chrono.cpp +++ src/chrono.cpp @@ -75,8 +75,19 @@ steady_clock::now() _NOEXCEPT { struct timespec tp; +#if defined(__APPLE__) && defined(CLOCK_UPTIME_RAW) + // CLOCK_MONOTONIC is only defined on Darwin on libc versions >= 1133 and + // its behaviour differs from Linux. + // CLOCK_UPTIME on Darwin actually matches CLOCK_MONOTONIC on Linux, due to + // historical coincidence (Linux doesn't match POSIX here but Darwin does). + // Use CLOCK_UPTIME_RAW on Darwin since the _RAW version gives nanosecond + // precision and is lower overhead. + if (0 != clock_gettime(CLOCK_UPTIME_RAW, &tp)) + __throw_system_error(errno, "clock_gettime(CLOCK_UPTIME_RAW) failed"); +#else if (0 != clock_gettime(CLOCK_MONOTONIC, &tp)) __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed"); +#endif return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec)); }