From db6492e15405e5bfa4fc99097dd866544b19a0ee Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Wed, 17 Dec 2014 10:45:43 -0800 Subject: [PATCH] win: clock implementation R=mark@chromium.org BUG=crashpad:1 Review URL: https://codereview.chromium.org/807973002 --- util/misc/clock.h | 6 ++++ util/misc/{clock.cc => clock_posix.cc} | 0 util/misc/clock_win.cc | 48 ++++++++++++++++++++++++++ util/util.gyp | 3 +- 4 files changed, 56 insertions(+), 1 deletion(-) rename util/misc/{clock.cc => clock_posix.cc} (100%) create mode 100644 util/misc/clock_win.cc diff --git a/util/misc/clock.h b/util/misc/clock.h index 88bdcd50..a07e12a6 100644 --- a/util/misc/clock.h +++ b/util/misc/clock.h @@ -17,6 +17,8 @@ #include +#include "build/build_config.h" + namespace crashpad { //! \brief Returns the value of the system’s monotonic clock. @@ -32,6 +34,8 @@ namespace crashpad { //! \return The value of the system’s monotonic clock, in nanoseconds. uint64_t ClockMonotonicNanoseconds(); +#if !defined(OS_WIN) // Not implemented on Windows yet. + //! \brief Sleeps for the specified duration. //! //! \param[in] nanoseconds The number of nanoseconds to sleep. The actual sleep @@ -41,6 +45,8 @@ uint64_t ClockMonotonicNanoseconds(); //! being interrupted by a signal. void SleepNanoseconds(uint64_t nanoseconds); +#endif + } // namespace crashpad #endif // CRASHPAD_UTIL_MISC_CLOCK_H_ diff --git a/util/misc/clock.cc b/util/misc/clock_posix.cc similarity index 100% rename from util/misc/clock.cc rename to util/misc/clock_posix.cc diff --git a/util/misc/clock_win.cc b/util/misc/clock_win.cc new file mode 100644 index 00000000..731e98d4 --- /dev/null +++ b/util/misc/clock_win.cc @@ -0,0 +1,48 @@ +// Copyright 2014 The Crashpad Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "util/misc/clock.h" + +#include +#include + +namespace { + +LARGE_INTEGER QpcFrequencyInternal() { + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + return frequency; +} + +int64_t QpcFrequency() { + static LARGE_INTEGER frequency = QpcFrequencyInternal(); + return frequency.QuadPart; +} + +} // namespace + +namespace crashpad { + +uint64_t ClockMonotonicNanoseconds() { + LARGE_INTEGER time; + QueryPerformanceCounter(&time); + int64_t frequency = QpcFrequency(); + int64_t whole_seconds = time.QuadPart / frequency; + int64_t leftover_ticks = time.QuadPart / (whole_seconds * frequency); + const int64_t kNanosecondsPerSecond = static_cast(1E9); + return (whole_seconds * kNanosecondsPerSecond) + + ((leftover_ticks * kNanosecondsPerSecond) / frequency); +} + +} // namespace crashpad diff --git a/util/util.gyp b/util/util.gyp index 2882b046..6ec762f3 100644 --- a/util/util.gyp +++ b/util/util.gyp @@ -72,9 +72,10 @@ 'mach/task_for_pid.h', 'mach/task_memory.cc', 'mach/task_memory.h', - 'misc/clock.cc', 'misc/clock.h', 'misc/clock_mac.cc', + 'misc/clock_posix.cc', + 'misc/clock_win.cc', 'misc/initialization_state.h', 'misc/initialization_state_dcheck.cc', 'misc/initialization_state_dcheck.h',