#pragma once #include "mutex.h" #include #include #include #include class TCondVar { public: TCondVar(); ~TCondVar(); void BroadCast() noexcept; void Signal() noexcept; /* * returns false if failed by timeout */ bool WaitD(TMutex& m, TInstant deadline) noexcept; template inline bool WaitD(TMutex& m, TInstant deadline, P pred) noexcept { while (!pred()) { if (!WaitD(m, deadline)) { return pred(); } } return true; } /* * returns false if failed by timeout */ inline bool WaitT(TMutex& m, TDuration timeout) noexcept { return WaitD(m, timeout.ToDeadLine()); } template inline bool WaitT(TMutex& m, TDuration timeout, P pred) noexcept { return WaitD(m, timeout.ToDeadLine(), std::move(pred)); } /* * infinite wait */ inline void WaitI(TMutex& m) noexcept { WaitD(m, TInstant::Max()); } template inline void WaitI(TMutex& m, P pred) noexcept { WaitD(m, TInstant::Max(), std::move(pred)); } // deprecated inline void Wait(TMutex& m) noexcept { WaitI(m); } template inline void Wait(TMutex& m, P pred) noexcept { WaitI(m, std::move(pred)); } private: class TImpl; THolder Impl_; };