Chromium Code Reviews| Index: util/misc/clock_win.cc |
| diff --git a/util/misc/clock.cc b/util/misc/clock_win.cc |
| similarity index 53% |
| rename from util/misc/clock.cc |
| rename to util/misc/clock_win.cc |
| index 24171091db1d41db1c34b420eb197b8291220214..a411cf63e4b76813ccef4b7a2bbc6d0a56fe60a8 100644 |
| --- a/util/misc/clock.cc |
| +++ b/util/misc/clock_win.cc |
| @@ -14,38 +14,31 @@ |
| #include "util/misc/clock.h" |
| -#include <time.h> |
| - |
| -#include "base/logging.h" |
| -#include "base/posix/eintr_wrapper.h" |
| -#include "build/build_config.h" |
| - |
| -namespace { |
| - |
| -const uint64_t kNanosecondsPerSecond = 1E9; |
| - |
| -} // namespace |
| +#include <windows.h> |
| namespace crashpad { |
| -#if !defined(OS_MACOSX) |
| - |
| uint64_t ClockMonotonicNanoseconds() { |
| - timespec now; |
| - int rv = clock_gettime(CLOCK_MONOTONIC, &now); |
| - DPCHECK(rv == 0) << "clock_gettime"; |
| + LARGE_INTEGER frequency; |
| + LARGE_INTEGER time; |
| - return now.tv_sec * kNanosecondsPerSecond + now.tv_nsec; |
| -} |
| + QueryPerformanceFrequency(&frequency); |
|
Mark Mentovai
2014/12/16 23:06:54
Cache this like we do in clock_mac.cc? (TimebaseIn
Mark Mentovai
2014/12/16 23:06:54
PCHECK() or DPCHECK() this and QueryPerformanceCou
scottmg
2014/12/17 01:01:28
Done.
scottmg
2014/12/17 01:01:28
They can't fail on XP or later, so I prefer not to
|
| + QueryPerformanceCounter(&time); |
| -#endif |
| + // |time| is the elapsed number of ticks, and we have the number of |
| + // ticks-per-second. Use this to convert to the number of nanoseconds. |
| + time.QuadPart *= 1000000000; |
|
Mark Mentovai
2014/12/16 23:06:54
Fear of overflow: what kind of number is frequency
Mark Mentovai
2014/12/16 23:06:54
1E9 or kNanosecondsPerSecond = 1E9?
scottmg
2014/12/17 01:01:28
Done.
scottmg
2014/12/17 01:01:28
Done.
|
| + time.QuadPart /= frequency.QuadPart; |
| + |
| + return time.QuadPart; |
| +} |
| void SleepNanoseconds(uint64_t nanoseconds) { |
| - timespec sleep_time; |
| - sleep_time.tv_sec = nanoseconds / kNanosecondsPerSecond; |
| - sleep_time.tv_nsec = nanoseconds % kNanosecondsPerSecond; |
| - int rv = HANDLE_EINTR(nanosleep(&sleep_time, &sleep_time)); |
| - DPCHECK(rv == 0) << "nanosleep"; |
| + // This is both inaccurate (will be way too long for short sleeps) and |
| + // incorrect (can sleep for less than requested). But it's what's available |
| + // without implementing a busy loop. |
| + const uint64_t kNanosecondsPerMillisecond = 1000000; |
|
Mark Mentovai
2014/12/16 23:06:54
1E6? Counting more than four identical characters
scottmg
2014/12/17 01:01:28
Done.
|
| + ::Sleep(static_cast<DWORD>(nanoseconds / kNanosecondsPerMillisecond)); |
|
Mark Mentovai
2014/12/16 23:06:54
The :: isn’t necessary, unless they’re so strongly
scottmg
2014/12/17 01:01:28
Done.
|
| } |
| } // namespace crashpad |