diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-02 10:45:56 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-02 10:45:56 -0700 |
| commit | dde0adcb363f3a3f306c0fc9eaec511cc3b74965 (patch) | |
| tree | 9388d039a0b77211936c7264f5a3179f63ad51e6 /lib/libcxx/src/chrono.cpp | |
| parent | c4cd592f0e1eeff5a4056796610d97010ae4e38c (diff) | |
| parent | 7a2624c3e40e2386a4a8a775b839e1d67608ec42 (diff) | |
| download | zig-dde0adcb363f3a3f306c0fc9eaec511cc3b74965.tar.gz zig-dde0adcb363f3a3f306c0fc9eaec511cc3b74965.zip | |
Merge branch 'llvm13'
Diffstat (limited to 'lib/libcxx/src/chrono.cpp')
| -rw-r--r-- | lib/libcxx/src/chrono.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/libcxx/src/chrono.cpp b/lib/libcxx/src/chrono.cpp index 085fbfde26..13b375947b 100644 --- a/lib/libcxx/src/chrono.cpp +++ b/lib/libcxx/src/chrono.cpp @@ -6,9 +6,20 @@ // //===----------------------------------------------------------------------===// +#if defined(__MVS__) +// As part of monotonic clock support on z/OS we need macro _LARGE_TIME_API +// to be defined before any system header to include definition of struct timespec64. +#define _LARGE_TIME_API +#endif + #include "chrono" #include "cerrno" // errno #include "system_error" // __throw_system_error + +#if defined(__MVS__) +#include <__support/ibm/gettod_zos.h> // gettimeofdayMonotonic +#endif + #include <time.h> // clock_gettime and CLOCK_{MONOTONIC,REALTIME,MONOTONIC_RAW} #include "include/apple_availability.h" @@ -20,7 +31,7 @@ # include <sys/time.h> // for gettimeofday and timeval #endif -#if !defined(__APPLE__) && _POSIX_TIMERS > 0 +#if !defined(__APPLE__) && defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 # define _LIBCPP_USE_CLOCK_GETTIME #endif @@ -96,19 +107,19 @@ static system_clock::time_point __libcpp_system_clock_now() { const bool system_clock::is_steady; system_clock::time_point -system_clock::now() _NOEXCEPT +system_clock::now() noexcept { return __libcpp_system_clock_now(); } time_t -system_clock::to_time_t(const time_point& t) _NOEXCEPT +system_clock::to_time_t(const time_point& t) noexcept { return time_t(duration_cast<seconds>(t.time_since_epoch()).count()); } system_clock::time_point -system_clock::from_time_t(time_t t) _NOEXCEPT +system_clock::from_time_t(time_t t) noexcept { return system_clock::time_point(seconds(t)); } @@ -218,6 +229,16 @@ static steady_clock::time_point __libcpp_steady_clock_now() { return steady_clock::time_point(steady_clock::duration(dur)); } +#elif defined(__MVS__) + +static steady_clock::time_point __libcpp_steady_clock_now() { + struct timespec64 ts; + if (0 != gettimeofdayMonotonic(&ts)) + __throw_system_error(errno, "failed to obtain time of day"); + + return steady_clock::time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec)); +} + #elif defined(CLOCK_MONOTONIC) static steady_clock::time_point __libcpp_steady_clock_now() { @@ -234,7 +255,7 @@ static steady_clock::time_point __libcpp_steady_clock_now() { const bool steady_clock::is_steady; steady_clock::time_point -steady_clock::now() _NOEXCEPT +steady_clock::now() noexcept { return __libcpp_steady_clock_now(); } |
