1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 23:03:53 -04:00

std::condition_variable_any -> std::condition_variable

The latter is supposed to be more efficient.
This commit is contained in:
Eelco Dolstra 2016-02-24 13:31:46 +01:00
parent ccdbf589a4
commit bf2adf72c4
2 changed files with 11 additions and 11 deletions

View file

@ -54,7 +54,7 @@ private:
Sync<State> state; Sync<State> state;
std::condition_variable_any wakeup; std::condition_variable wakeup;
public: public:

View file

@ -38,37 +38,37 @@ public:
{ {
private: private:
Sync * s; Sync * s;
std::unique_lock<std::mutex> lk;
friend Sync; friend Sync;
Lock(Sync * s) : s(s) { s->mutex.lock(); } Lock(Sync * s) : s(s), lk(s->mutex) { }
public: public:
Lock(Lock && l) : s(l.s) { l.s = 0; } Lock(Lock && l) : s(l.s) { abort(); }
Lock(const Lock & l) = delete; Lock(const Lock & l) = delete;
~Lock() { if (s) s->mutex.unlock(); } ~Lock() { }
T * operator -> () { return &s->data; } T * operator -> () { return &s->data; }
T & operator * () { return s->data; } T & operator * () { return s->data; }
/* FIXME: performance impact of condition_variable_any? */ void wait(std::condition_variable & cv)
void wait(std::condition_variable_any & cv)
{ {
assert(s); assert(s);
cv.wait(s->mutex); cv.wait(lk);
} }
template<class Rep, class Period, class Predicate> template<class Rep, class Period, class Predicate>
bool wait_for(std::condition_variable_any & cv, bool wait_for(std::condition_variable & cv,
const std::chrono::duration<Rep, Period> & duration, const std::chrono::duration<Rep, Period> & duration,
Predicate pred) Predicate pred)
{ {
assert(s); assert(s);
return cv.wait_for(s->mutex, duration, pred); return cv.wait_for(lk, duration, pred);
} }
template<class Clock, class Duration> template<class Clock, class Duration>
std::cv_status wait_until(std::condition_variable_any & cv, std::cv_status wait_until(std::condition_variable & cv,
const std::chrono::time_point<Clock, Duration> & duration) const std::chrono::time_point<Clock, Duration> & duration)
{ {
assert(s); assert(s);
return cv.wait_until(s->mutex, duration); return cv.wait_until(lk, duration);
} }
}; };