mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +00:00
Retire ConditionVariable
Now that we use spinlocks everywhere and don't put threads to sleep while idle, we can use the slower (but no more in hot path) std::condition_variable_any instead of our homwgrown ConditionVariable struct. Verified fo rno regression at STC with 7 threads: ELO: -0.66 +-2.7 (95%) LOS: 31.8% Total: 20000 W: 3210 L: 3248 D: 13542 No functional change
This commit is contained in:
parent
966bc477af
commit
ebf3735754
1 changed files with 1 additions and 23 deletions
|
@ -57,29 +57,7 @@ private:
|
||||||
CRITICAL_SECTION cs;
|
CRITICAL_SECTION cs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConditionVariable {
|
typedef std::condition_variable_any ConditionVariable;
|
||||||
ConditionVariable() { hn = CreateEvent(0, FALSE, FALSE, 0); }
|
|
||||||
~ConditionVariable() { CloseHandle(hn); }
|
|
||||||
void notify_one() { SetEvent(hn); }
|
|
||||||
|
|
||||||
void wait(std::unique_lock<Mutex>& lk) {
|
|
||||||
lk.unlock();
|
|
||||||
WaitForSingleObject(hn, INFINITE);
|
|
||||||
lk.lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wait_for(std::unique_lock<Mutex>& lk, const std::chrono::milliseconds& ms) {
|
|
||||||
lk.unlock();
|
|
||||||
WaitForSingleObject(hn, ms.count());
|
|
||||||
lk.lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Predicate>
|
|
||||||
void wait(std::unique_lock<Mutex>& lk, Predicate p) { while (!p()) this->wait(lk); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
HANDLE hn;
|
|
||||||
};
|
|
||||||
|
|
||||||
#else // Default case: use STL classes
|
#else // Default case: use STL classes
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue