Removing uses of Sleep/SwitchToThread/etc.

This commit is contained in:
Ben Vanik
2015-07-13 21:54:24 -07:00
parent 40621a90bd
commit d89bad7380
8 changed files with 23 additions and 13 deletions

View File

@@ -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>

View File

@@ -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));
}