|
31 | 31 | # include <sys/time.h> // for gettimeofday and timeval |
32 | 32 | #endif |
33 | 33 |
|
| 34 | +#if defined(__LLVM_LIBC__) |
| 35 | +# define _LIBCPP_HAS_TIMESPEC_GET |
| 36 | +#endif |
| 37 | + |
34 | 38 | // OpenBSD and GPU do not have a fully conformant suite of POSIX timers, but |
35 | 39 | // it does have clock_gettime and CLOCK_MONOTONIC which is all we need. |
36 | 40 | #if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || defined(__AMDGPU__) || \ |
@@ -115,6 +119,15 @@ static system_clock::time_point __libcpp_system_clock_now() { |
115 | 119 | return system_clock::time_point(duration_cast<system_clock::duration>(d - nt_to_unix_epoch)); |
116 | 120 | } |
117 | 121 |
|
| 122 | +#elif defined(_LIBCPP_HAS_TIMESPEC_GET) |
| 123 | + |
| 124 | +static system_clock::time_point __libcpp_system_clock_now() { |
| 125 | + struct timespec ts; |
| 126 | + if (timespec_get(&ts, TIME_UTC) != TIME_UTC) |
| 127 | + __throw_system_error(errno, "timespec_get(TIME_UTC) failed"); |
| 128 | + return system_clock::time_point(seconds(ts.tv_sec) + microseconds(ts.tv_nsec / 1000)); |
| 129 | +} |
| 130 | + |
118 | 131 | #elif defined(_LIBCPP_HAS_CLOCK_GETTIME) |
119 | 132 |
|
120 | 133 | static system_clock::time_point __libcpp_system_clock_now() { |
@@ -216,6 +229,15 @@ static steady_clock::time_point __libcpp_steady_clock_now() noexcept { |
216 | 229 | return steady_clock::time_point(nanoseconds(_zx_clock_get_monotonic())); |
217 | 230 | } |
218 | 231 |
|
| 232 | +# elif defined(_LIBCPP_HAS_TIMESPEC_GET) |
| 233 | + |
| 234 | +static steady_clock::time_point __libcpp_steady_clock_now() { |
| 235 | + struct timespec ts; |
| 236 | + if (timespec_get(&ts, TIME_MONOTONIC) != TIME_MONOTONIC) |
| 237 | + __throw_system_error(errno, "timespec_get(TIME_MONOTONIC) failed"); |
| 238 | + return steady_clock::time_point(seconds(ts.tv_sec) + microseconds(ts.tv_nsec / 1000)); |
| 239 | +} |
| 240 | + |
219 | 241 | # elif defined(_LIBCPP_HAS_CLOCK_GETTIME) |
220 | 242 |
|
221 | 243 | static steady_clock::time_point __libcpp_steady_clock_now() { |
|
0 commit comments