mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-08 21:26:04 +00:00
win: clock implementation
R=mark@chromium.org BUG=crashpad:1 Review URL: https://codereview.chromium.org/807973002
This commit is contained in:
parent
86cf286350
commit
db6492e154
@ -17,6 +17,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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_
|
||||
|
48
util/misc/clock_win.cc
Normal file
48
util/misc/clock_win.cc
Normal file
@ -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 <sys/types.h>
|
||||
#include <windows.h>
|
||||
|
||||
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<const int64_t>(1E9);
|
||||
return (whole_seconds * kNanosecondsPerSecond) +
|
||||
((leftover_ticks * kNanosecondsPerSecond) / frequency);
|
||||
}
|
||||
|
||||
} // namespace crashpad
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user