Removing uses of Sleep/SwitchToThread/etc.
This commit is contained in:
@@ -57,6 +57,9 @@ void set_name(std::thread::native_handle_type handle, const std::string& name);
|
||||
// Yields the current thread to the scheduler. Maybe.
|
||||
void MaybeYield();
|
||||
|
||||
// Memory barrier (request - may be ignored).
|
||||
void SyncMemory();
|
||||
|
||||
// Sleeps the current thread for at least as long as the given duration.
|
||||
void Sleep(std::chrono::microseconds duration);
|
||||
template <typename Rep, typename Period>
|
||||
|
||||
@@ -52,11 +52,16 @@ void set_name(std::thread::native_handle_type handle, const std::string& name) {
|
||||
set_name(GetThreadId(handle), name);
|
||||
}
|
||||
|
||||
void MaybeYield() { SwitchToThread(); }
|
||||
void MaybeYield() {
|
||||
SwitchToThread();
|
||||
MemoryBarrier();
|
||||
}
|
||||
|
||||
void SyncMemory() { MemoryBarrier(); }
|
||||
|
||||
void Sleep(std::chrono::microseconds duration) {
|
||||
if (duration.count() < 100) {
|
||||
SwitchToThread();
|
||||
MaybeYield();
|
||||
} else {
|
||||
::Sleep(static_cast<DWORD>(duration.count() / 1000));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user