mirror of
https://github.com/chromium/crashpad.git
synced 2025-01-14 09:17:57 +08:00
Implement SleepNanoseconds() on Windows.
This uses the naïve implementation originally written https://codereview.chromium.org/807973002/#ps180001. Bug: crashpad:192 Change-Id: Id00908dafb8886d6163a8b17213d3b7c33b81963 Reviewed-on: https://chromium-review.googlesource.com/606998 Commit-Queue: Robert Sesek <rsesek@chromium.org> Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
01110c0a3b
commit
f16e4eb9ff
@ -34,19 +34,15 @@ 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
|
||||
//! may be slightly longer due to latencies and timer resolution.
|
||||
//!
|
||||
//! This function is resilient against the underlying `nanosleep()` system call
|
||||
//! being interrupted by a signal.
|
||||
//! On POSIX, this function is resilient against the underlying `nanosleep()`
|
||||
//! system call being interrupted by a signal.
|
||||
void SleepNanoseconds(uint64_t nanoseconds);
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace crashpad
|
||||
|
||||
#endif // CRASHPAD_UTIL_MISC_CLOCK_H_
|
||||
|
@ -45,4 +45,12 @@ uint64_t ClockMonotonicNanoseconds() {
|
||||
((leftover_ticks * kNanosecondsPerSecond) / frequency);
|
||||
}
|
||||
|
||||
void SleepNanoseconds(uint64_t nanoseconds) {
|
||||
// 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.
|
||||
constexpr uint64_t kNanosecondsPerMillisecond = static_cast<uint64_t>(1E6);
|
||||
Sleep(static_cast<DWORD>(nanoseconds / kNanosecondsPerMillisecond));
|
||||
}
|
||||
|
||||
} // namespace crashpad
|
||||
|
Loading…
x
Reference in New Issue
Block a user