AtomicCondition: add wait_for with predicate, add notify_one

This commit is contained in:
Tom 2019-09-16 18:07:58 +02:00
parent 1146362559
commit 5708d49a1a

View File

@ -44,6 +44,22 @@ public:
return; return;
} }
template<class Rep, class Period, class Predicate>
void wait_for(const std::chrono::duration<Rep, Period>& time,
Predicate pred) const
{
std::unique_lock<std::mutex> lock(this->condvar_mutex_);
while( !pred() )
if( this->condvar_.wait_for(lock, time) == std::cv_status::timeout )
return;
}
void notify_one() noexcept
{
this->condvar_.notify_one();
}
void notify_all() noexcept void notify_all() noexcept
{ {
this->condvar_.notify_all(); this->condvar_.notify_all();