26#ifndef MYSQL_HARNESS_STDX_MONITOR_H_INCLUDED
27#define MYSQL_HARNESS_STDX_MONITOR_H_INCLUDED
29#include <condition_variable>
45 std::lock_guard<std::mutex> lk{
mtx_};
68 std::lock_guard<std::mutex> lk{this->
mtx_};
70 return f(this->
t_,
cv_);
79 template <
class Rep,
class Period,
class Pred>
80 auto wait_for(
const std::chrono::duration<Rep, Period> &rel_time, Pred pred) {
81 std::unique_lock<std::mutex> lk{this->
mtx_};
83 return cv_.wait_for(lk, rel_time,
84 [
this, pred]() {
return pred(this->
t_); });
88 auto wait(Pred pred)
const {
89 std::unique_lock<std::mutex> lk{this->
mtx_};
91 return cv_.wait(lk, [
this, pred]() {
return pred(this->
t_); });
95 mutable std::condition_variable
cv_;
Monitor pattern.
Definition: monitor.h:39
Monitor(T t)
Definition: monitor.h:41
std::mutex mtx_
Definition: monitor.h:53
T t_
Definition: monitor.h:51
auto operator()(F f) const
Definition: monitor.h:44
Monitor can be waited for.
Definition: monitor.h:62
auto serialize_with_cv(F f) const
Definition: monitor.h:67
std::condition_variable cv_
Definition: monitor.h:95
auto wait(Pred pred) const
Definition: monitor.h:88
auto wait_for(const std::chrono::duration< Rep, Period > &rel_time, Pred pred)
wait_for time or pred is true.
Definition: monitor.h:80
Definition: gcs_xcom_synode.h:64