diff --git a/src/libutil/include/nix/util/sync.hh b/src/libutil/include/nix/util/sync.hh index ad640410a46..6f3298324ff 100644 --- a/src/libutil/include/nix/util/sync.hh +++ b/src/libutil/include/nix/util/sync.hh @@ -27,7 +27,7 @@ namespace nix { * Here, "data" is automatically unlocked when "data_" goes out of * scope. */ -template +template class SyncBase { private: @@ -76,29 +76,35 @@ public: ~Lock() {} - void wait(std::condition_variable & cv) + void wait(CV & cv) { assert(s); cv.wait(lk); } + template + void wait(CV & cv, Predicate pred) + { + assert(s); + cv.wait(lk, std::move(pred)); + } + template - std::cv_status wait_for(std::condition_variable & cv, const std::chrono::duration & duration) + std::cv_status wait_for(CV & cv, const std::chrono::duration & duration) { assert(s); return cv.wait_for(lk, duration); } template - bool wait_for(std::condition_variable & cv, const std::chrono::duration & duration, Predicate pred) + bool wait_for(CV & cv, const std::chrono::duration & duration, Predicate pred) { assert(s); return cv.wait_for(lk, duration, pred); } template - std::cv_status - wait_until(std::condition_variable & cv, const std::chrono::time_point & duration) + std::cv_status wait_until(CV & cv, const std::chrono::time_point & duration) { assert(s); return cv.wait_until(lk, duration); @@ -154,10 +160,15 @@ public: }; template -using Sync = SyncBase, std::unique_lock>; +using Sync = + SyncBase, std::unique_lock, std::condition_variable>; template -using SharedSync = - SyncBase, std::shared_lock>; +using SharedSync = SyncBase< + T, + std::shared_mutex, + std::unique_lock, + std::shared_lock, + std::condition_variable>; } // namespace nix