diff --git a/include/sgnl/AtomicCondition.h b/include/sgnl/AtomicCondition.h index 0835efd..7e30b28 100644 --- a/include/sgnl/AtomicCondition.h +++ b/include/sgnl/AtomicCondition.h @@ -44,6 +44,22 @@ public: return; } + template + void wait_for(const std::chrono::duration& time, + Predicate pred) const + { + std::unique_lock 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 { this->condvar_.notify_all();