[PATCH] [libcxx] Partially address a FIXME in steady_clock::now()
Aaron Ballman
aaron at aaronballman.com
Wed Jun 18 11:17:13 PDT 2014
On Fri, Jun 6, 2014 at 1:08 PM, Jon Roelofs <jonathan at codesourcery.com> wrote:
> Hi mclow.lists,
>
> http://reviews.llvm.org/D4045
>
> Files:
> libcxx/src/chrono.cpp
>
> Index: libcxx/src/chrono.cpp
> ===================================================================
> --- libcxx/src/chrono.cpp
> +++ libcxx/src/chrono.cpp
> @@ -108,11 +108,6 @@
> }
>
> #else // __APPLE__
> -// FIXME: We assume that clock_gettime(CLOCK_MONOTONIC) works on
> -// non-apple systems. Instead, we should check _POSIX_TIMERS and
> -// _POSIX_MONOTONIC_CLOCK and fall back to something else if those
> -// don't exist.
> -
> // Warning: If this is not truly steady, then it is non-conforming. It is
> // better for it to not exist and have the rest of libc++ use system_clock
> // instead.
> @@ -120,10 +115,18 @@
> steady_clock::time_point
> steady_clock::now() _NOEXCEPT
> {
> +#if (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) && \
> + (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0)
> struct timespec tp;
> if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
> __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
> return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
> +#else
> +#warning According to unistd.h, there is no monotonic clock on this system so \
> + we're falling back to std::system_clock (which may not be \
> + monotonic, and therefore may not be conforming).
This is presuming that the compiler being used to compile libc++
understands what #warning is, which ties us to compiler
implementations. So, for instance, this code will fail to compile
entirely with MSVC.
> + return time_point(system_clock::now().time_since_epoch());
> +#endif
> }
> #endif // __APPLE__
~Aaron
More information about the cfe-commits
mailing list