19 #ifndef LUNCHBOX_MONITOR_H    20 #define LUNCHBOX_MONITOR_H    22 #include <lunchbox/scopedMutex.h>     25 #include <boost/bind.hpp>    26 #include <condition_variable>    49     void bool_true()
 const {}
    76         std::unique_lock<std::mutex> lock(_mutex);
    78         _condition.notify_all();
    85         std::unique_lock<std::mutex> lock(_mutex);
    87         _condition.notify_all();
   108         std::unique_lock<std::mutex> lock(_mutex);
   110         _condition.notify_all();
   117         std::unique_lock<std::mutex> lock(_mutex);
   119         _condition.notify_all();
   124     T 
set(
const T& value)
   126         std::unique_lock<std::mutex> lock(_mutex);
   127         const T old = _value;
   129         _condition.notify_all();
   143         return _wait([&] { 
return _value == value; });
   153         return _wait([&] { 
return _value != value; });
   161     const T 
waitNE(
const T& v1, 
const T& v2)
 const   163         std::unique_lock<std::mutex> lock(_mutex);
   164         _condition.wait(lock, [&] { 
return _value != v1 && _value != v2; });
   175         return _wait([&] { 
return _value >= value; });
   185         return _wait([&] { 
return _value <= value; });
   195         return _wait([&] { 
return _value > value; });
   205         return _wait([&] { 
return _value < value; });
   219         return _timedWait([&] { 
return _value == value; }, timeout);
   231         return _timedWait([&] { 
return _value != value; }, timeout);
   243         return _timedWait([&] { 
return _value >= value; }, timeout);
   255         return _timedWait([&] { 
return _value <= value; }, timeout);
   267         return _timedWait([&] { 
return _value > value; }, timeout);
   279         return _timedWait([&] { 
return _value < value; }, timeout);
   286     bool operator==(
const T& value)
 const   288         std::unique_lock<std::mutex> lock(_mutex);
   289         return _value == value;
   291     bool operator!=(
const T& value)
 const   293         std::unique_lock<std::mutex> lock(_mutex);
   294         return _value != value;
   296     bool operator<(
const T& value)
 const   298         std::unique_lock<std::mutex> lock(_mutex);
   299         return _value < value;
   301     bool operator>(
const T& value)
 const   303         std::unique_lock<std::mutex> lock(_mutex);
   304         return _value > value;
   306     bool operator<=(
const T& value)
 const   308         std::unique_lock<std::mutex> lock(_mutex);
   309         return _value <= value;
   311     bool operator>=(
const T& value)
 const   313         std::unique_lock<std::mutex> lock(_mutex);
   314         return _value >= value;
   319         std::unique_lock<std::mutex> lock(_mutex);
   320         return _value == rhs._value;
   324         std::unique_lock<std::mutex> lock(_mutex);
   325         return _value != rhs._value;
   327     bool operator<(const Monitor<T>& rhs) 
const   329         std::unique_lock<std::mutex> lock(_mutex);
   330         return _value < rhs._value;
   334         std::unique_lock<std::mutex> lock(_mutex);
   335         return _value > rhs._value;
   337     bool operator<=(const Monitor<T>& rhs) 
const   339         std::unique_lock<std::mutex> lock(_mutex);
   340         return _value <= rhs._value;
   344         std::unique_lock<std::mutex> lock(_mutex);
   345         return _value >= rhs._value;
   350         std::unique_lock<std::mutex> lock(_mutex);
   360     const T& 
get() 
const { 
return _value; }
   364         std::unique_lock<std::mutex> lock(_mutex);
   365         return _value + value;
   371         std::unique_lock<std::mutex> lock(_mutex);
   372         return static_cast<T
>(_value | value);
   378         std::unique_lock<std::mutex> lock(_mutex);
   379         return static_cast<T
>(_value & value);
   385     mutable std::mutex _mutex;
   386     mutable std::condition_variable _condition;
   388     template <
typename F>
   389     const T _wait(
const F& predicate)
 const   391         std::unique_lock<std::mutex> lock(_mutex);
   392         _condition.wait(lock, predicate);
   396     template <
typename F>
   397     bool _timedWait(
const F& predicate, 
const uint32_t timeout)
 const   399         std::unique_lock<std::mutex> lock(_mutex);
   400         return _condition.wait_for(lock, std::chrono::milliseconds(timeout),
   409 template <
typename T>
   410 inline std::ostream& operator<<(std::ostream& os, const Monitor<T>& monitor)
   412     os << 
"Monitor< " << monitor.get() << 
" >";
   419     std::unique_lock<std::mutex> lock(_mutex);
   422     _condition.notify_all();
   429     std::unique_lock<std::mutex> lock(_mutex);
   432     _condition.notify_all();
   441         std::unique_lock<std::mutex> lock(_mutex);
   443         _condition.notify_all();
   449 #include <servus/uint128_t.h>   458 #endif // LUNCHBOX_MONITOR_H const T waitGE(const T &value) const 
Block until the monitor has a value greater or equal to the given value. 
 
bool timedWaitLT(const T &value, const uint32_t timeout) const 
Block until the monitor has a value less than the given value. 
 
Basic type definitions not provided by the operating system. 
 
const T & operator->() const 
 
const T waitLT(const T &value) const 
Block until the monitor has a value less than the given value. 
 
T operator|(const T &value) const 
 
Monitor(const T &value)
Construct a new monitor with a given default value. 
 
bool timedWaitGT(const T &value, const uint32_t timeout) const 
Block until the monitor has a value greater than the given value. 
 
const T waitLE(const T &value) const 
Block until the monitor has a value less or equal to the given value. 
 
Monitor & operator--()
Decrement the monitored value, prefix only. 
 
const T waitNE(const T &value) const 
Block until the monitor has not the given value. 
 
bool timedWaitGE(const T &value, const uint32_t timeout) const 
Block until the monitor has a value greater or equal to the given value. 
 
const T waitNE(const T &v1, const T &v2) const 
Block until the monitor has none of the given values. 
 
bool timedWaitNE(const T &value, const uint32_t timeout) const 
Block until the monitor has not the given value. 
 
Monitor(const Monitor< T > &from)
Ctor initializing with the given monitor value. 
 
Monitor & operator|=(const T &value)
Perform an or operation on the value. 
 
Monitor & operator=(const T &value)
Assign a new value. 
 
Monitor & operator&=(const T &value)
Perform an and operation on the value. 
 
T operator&(const T &value) const 
 
Monitor()
Construct a new monitor with a default value of 0. 
 
Monitor< uint32_t > Monitoru
An unsigned 32bit integer monitor. 
 
Abstraction layer and common utilities for multi-threaded programming. 
 
bool timedWaitEQ(const T &value, const uint32_t timeout) const 
Block until the monitor has the given value. 
 
const Monitor & operator=(const Monitor< T > &from)
Assign a new value. 
 
bool timedWaitLE(const T &value, const uint32_t timeout) const 
Block until the monitor has a value less or equal to the given value. 
 
const T waitGT(const T &value) const 
Block until the monitor has a value greater than the given value. 
 
Monitor & operator++()
Increment the monitored value, prefix only. 
 
T operator+(const T &value) const 
 
Monitor< bool > Monitorb
A boolean monitor variable. 
 
~Monitor()
Destructs the monitor. 
 
const T waitEQ(const T &value) const 
Block until the monitor has the given value.