17 #ifndef FOXXLL_COMMON_ONOFF_SWITCH_HEADER 18 #define FOXXLL_COMMON_ONOFF_SWITCH_HEADER 20 #include <condition_variable> 50 std::unique_lock<std::mutex> lock(mutex_);
58 std::unique_lock<std::mutex> lock(mutex_);
66 std::unique_lock<std::mutex> lock(mutex_);
74 std::unique_lock<std::mutex> lock(mutex_);
82 std::unique_lock<std::mutex> lock(mutex_);
89 #endif // !FOXXLL_COMMON_ONOFF_SWITCH_HEADER void wait_for_on()
wait for switch to turn ON
bool on_
the switch's state
std::condition_variable cond_
condition variable
void wait_for_off()
wait for switch to turn OFF
onoff_switch & operator=(const onoff_switch &)=delete
non-copyable: delete assignment operator
void off()
turn switch OFF and notify one waiter
void on()
turn switch ON and notify one waiter
onoff_switch(bool flag=false)
construct switch
bool is_on()
return true if switch is ON
std::mutex mutex_
mutex for condition variable