Skip to content
Snippets Groups Projects
Commit f5186193 authored by Philippe Gorley's avatar Philippe Gorley
Browse files

thread: wait until condition is fulfilled

Change-Id: I3a8f56aa4d93f73bd1290534e682f7d5f5025c5a
parent 945eec50
No related branches found
No related tags found
No related merge requests found
......@@ -114,6 +114,17 @@ public:
return cv_.wait_for(lk, rel_time, [this, pred]{ return isStopping() || pred(); });
}
template <typename Pred>
void
wait(Pred&& pred)
{
if (std::this_thread::get_id() != get_id())
throw std::runtime_error("Can not call wait outside thread context");
std::unique_lock<std::mutex> lk(mutex_);
cv_.wait(lk, [this, p = std::move(pred)]{ return isStopping() || p(); });
}
private:
std::mutex mutex_;
std::condition_variable cv_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment