Clocks: use CLOCK_[BOOTTIME,MONOTONIC_RAW] for Clocks::monotonic

GitOrigin-RevId: 729311e1a7a36a9245ecdb5921b81c4834ec1dc6
This commit is contained in:
Arseny Smirnov 2020-08-14 20:41:00 +03:00
parent 129e673769
commit 9c40e37288

View File

@ -25,26 +25,14 @@ double Clocks::monotonic() {
}
}
#endif
#ifdef CLOCK_UPTIME_RAW
#ifdef CLOCK_MONOTONIC_RAW
{
static bool skip = []() {
struct timespec spec;
return clock_gettime(CLOCK_UPTIME_RAW, &spec) != 0;
return clock_gettime(CLOCK_MONOTONIC_RAW, &spec) != 0;
}();
struct timespec spec;
if (!skip && clock_gettime(CLOCK_UPTIME_RAW, &spec) == 0) {
return static_cast<double>(spec.tv_nsec) * 1e-9 + static_cast<double>(spec.tv_sec);
}
}
#endif
#ifdef CLOCK_UPTIME
{
static bool skip = []() {
struct timespec spec;
return clock_gettime(CLOCK_UPTIME, &spec) != 0;
}();
struct timespec spec;
if (!skip && clock_gettime(CLOCK_UPTIME, &spec) == 0) {
if (!skip && clock_gettime(CLOCK_MONOTONIC_RAW, &spec) == 0) {
return static_cast<double>(spec.tv_nsec) * 1e-9 + static_cast<double>(spec.tv_sec);
}
}