Commit 248a4ac3 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Return the correct resolution for clock_getres

Summary: When the implementation of `clock_gettime` for `REALTIME` and `MONOTONIC` was switched to use `std::chrono`, this didn't get switched over to the resolution of the new implementation.

Reviewed By: yfeldblum

Differential Revision: D4150297

fbshipit-source-id: a4578af85cae538a3ebb6da7e759058927c31d3e
parent 9bb2b0df
......@@ -171,26 +171,22 @@ extern "C" int clock_getres(clockid_t clock_id, struct timespec* res) {
return -1;
}
switch (clock_id) {
case CLOCK_MONOTONIC: {
LARGE_INTEGER freq = performanceFrequency();
if (freq.QuadPart == -1) {
errno = EINVAL;
return -1;
}
static constexpr size_t kNsPerSec = 1000000000;
res->tv_sec = 0;
res->tv_nsec = (long)((kNsPerSec + (freq.QuadPart >> 1)) / freq.QuadPart);
if (res->tv_nsec < 1) {
res->tv_nsec = 1;
switch (clock_id) {
case CLOCK_REALTIME: {
constexpr auto perSec = double(std::chrono::system_clock::period::num) /
std::chrono::system_clock::period::den;
res->tv_sec = time_t(perSec);
res->tv_nsec = time_t(perSec * kNsPerSec);
return 0;
}
case CLOCK_MONOTONIC: {
constexpr auto perSec = double(std::chrono::steady_clock::period::num) /
std::chrono::steady_clock::period::den;
res->tv_sec = time_t(perSec);
res->tv_nsec = time_t(perSec * kNsPerSec);
return 0;
}
case CLOCK_REALTIME:
case CLOCK_PROCESS_CPUTIME_ID:
case CLOCK_THREAD_CPUTIME_ID: {
DWORD adj, timeIncrement;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment