diff options
author | dim <dim@FreeBSD.org> | 2015-10-06 17:53:29 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-10-06 17:53:29 +0000 |
commit | a6f4f28b545e1f0632ba4b20b86a7ab487932373 (patch) | |
tree | e9dbc6d658415636ba47d28716ee528c8ab7c862 /contrib/libc++/src/chrono.cpp | |
parent | 09f0c012db173aa7875b4d45fc67ef4d26c82548 (diff) | |
parent | 9ba87e73be0d01bbe1cf9547130ae12f9b15d7a7 (diff) | |
download | FreeBSD-src-a6f4f28b545e1f0632ba4b20b86a7ab487932373.zip FreeBSD-src-a6f4f28b545e1f0632ba4b20b86a7ab487932373.tar.gz |
Upgrade our copies of clang, llvm, lldb, compiler-rt and libc++ to 3.7.0
release.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm and clang can be found here:
<http://llvm.org/releases/3.7.0/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.7.0/tools/clang/docs/ReleaseNotes.html>
Thanks to Ed Maste, Andrew Turner and Antoine Brodin for their help.
Exp-run: antoine
Relnotes: yes
Diffstat (limited to 'contrib/libc++/src/chrono.cpp')
-rw-r--r-- | contrib/libc++/src/chrono.cpp | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/contrib/libc++/src/chrono.cpp b/contrib/libc++/src/chrono.cpp index 4569411..62149fb 100644 --- a/contrib/libc++/src/chrono.cpp +++ b/contrib/libc++/src/chrono.cpp @@ -8,14 +8,21 @@ //===----------------------------------------------------------------------===// #include "chrono" -#include <sys/time.h> //for gettimeofday and timeval -#ifdef __APPLE__ +#include "cerrno" // errno +#include "system_error" // __throw_system_error +#include <time.h> // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME + +#if !defined(CLOCK_REALTIME) +#include <sys/time.h> // for gettimeofday and timeval +#endif + +#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(CLOCK_MONOTONIC) +#if __APPLE__ #include <mach/mach_time.h> // mach_absolute_time, mach_timebase_info_data_t -#else /* !__APPLE__ */ -#include <cerrno> // errno -#include <system_error> // __throw_system_error -#include <time.h> // clock_gettime, CLOCK_MONOTONIC -#endif // __APPLE__ +#else +#error "Monotonic clock not implemented" +#endif +#endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -29,9 +36,16 @@ const bool system_clock::is_steady; system_clock::time_point system_clock::now() _NOEXCEPT { +#ifdef CLOCK_REALTIME + struct timespec tp; + if (0 != clock_gettime(CLOCK_REALTIME, &tp)) + __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed"); + return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000)); +#else // !CLOCK_REALTIME timeval tv; gettimeofday(&tv, 0); return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec)); +#endif // CLOCK_REALTIME } time_t @@ -48,10 +62,26 @@ system_clock::from_time_t(time_t t) _NOEXCEPT #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK // steady_clock +// +// 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. const bool steady_clock::is_steady; -#ifdef __APPLE__ +#ifdef CLOCK_MONOTONIC + +steady_clock::time_point +steady_clock::now() _NOEXCEPT +{ + 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)); +} + +#elif defined(__APPLE__) + // mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of // nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom // are run time constants supplied by the OS. This clock has no relationship @@ -108,23 +138,9 @@ steady_clock::now() _NOEXCEPT return time_point(duration(fp())); } -#else // __APPLE__ -// FIXME: if _LIBCPP_HAS_NO_MONOTONIC_CLOCK, then clock_gettime isn't going to -// work. It may be possible to fall back on something else, depending on the system. - -// 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. - -steady_clock::time_point -steady_clock::now() _NOEXCEPT -{ - 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)); -} -#endif // __APPLE__ +#else +#error "Monotonic clock not implemented" +#endif #endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK |