From a Darwin perspective, this LGTM (it's what we're shipping on macOS 10.12 
and iOS 10).

Eric, do you have a good idea for how to test this?

> On 2016-Dec-05, at 14:36, Bruno Cardoso Lopes via Phabricator 
> <revi...@reviews.llvm.org> wrote:
> 
> bruno created this revision.
> bruno added reviewers: mclow.lists, dexonsmith, EricWF.
> bruno added a subscriber: cfe-commits.
> 
> 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.
> 
> 
> https://reviews.llvm.org/D27429
> 
> Files:
>  src/chrono.cpp
> 
> 
> 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));
> }
> 
> 
> 
> <D27429.80328.patch>

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to