19 #ifndef LUNCHBOX_MONITOR_H
20 #define LUNCHBOX_MONITOR_H
22 #include <lunchbox/condition.h>
23 #include <lunchbox/scopedMutex.h>
45 void bool_true()
const {}
52 explicit Monitor(
const T& value ) : _value( value ) {}
113 void set(
const T& value )
130 if(
sizeof( T ) <= 8 && _value == value )
133 while( _value != value )
145 if(
sizeof( T ) <= 8 )
147 const T current = _value;
148 if( current != value )
152 while( _value == value )
162 const T
waitNE(
const T& v1,
const T& v2 )
const
164 if(
sizeof( T ) <= 8 )
166 const T current = _value;
167 if( current != v1 && current != v2 )
171 while( _value == v1 || _value == v2 )
183 if(
sizeof( T ) <= 8 )
185 const T current = _value;
186 if( current >= value )
190 while( _value < value )
201 if(
sizeof( T ) <= 8 )
203 const T current = _value;
204 if( current <= value )
208 while( _value > value )
224 if(
sizeof( T ) <= 8 && _value == value )
228 while( _value != value )
247 if(
sizeof( T ) <= 8 && _value >= value )
251 while( _value < value )
270 if(
sizeof( T ) <= 8 && _value != value )
274 while( _value == value )
287 bool operator == (
const T& value )
const
290 return _value == value;
292 bool operator != (
const T& value )
const
295 return _value != value;
297 bool operator < (
const T& value )
const
300 return _value < value;
302 bool operator > (
const T& value )
const
305 return _value > value;
307 bool operator <= (
const T& value )
const
310 return _value <= value;
312 bool operator >= (
const T& value )
const
315 return _value >= value;
318 bool operator == (
const Monitor<T>& rhs )
const
321 return _value == rhs._value;
323 bool operator != (
const Monitor<T>& rhs )
const
326 return _value != rhs._value;
328 bool operator < ( const Monitor<T>& rhs )
const
331 return _value < rhs._value;
333 bool operator > (
const Monitor<T>& rhs )
const
336 return _value > rhs._value;
338 bool operator <= ( const Monitor<T>& rhs )
const
341 return _value <= rhs._value;
343 bool operator >= (
const Monitor<T>& rhs )
const
346 return _value >= rhs._value;
362 const T&
get()
const {
return _value; }
368 return _value + value;
375 return static_cast< T
>( _value | value );
382 return static_cast< T
>( _value & value );
395 template<
typename T >
399 os <<
"Monitor< " << monitor.
get() <<
" >";
434 #include <lunchbox/uint128_t.h>
440 #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.
LUNCHBOX_API bool timedWait(const uint32_t timeout)
Atomically unlock the mutex, wait for a signal and relock the mutex.
Basic type definitions not provided by the operating system.
A condition variable and associated lock.
ScopedMutex< Condition, WriteOp > ScopedCondition
A scoped mutex for a write operation on a condition.
const T & waitEQ(const T &value) const
Block until the monitor has the given value.
const T & operator->() const
Monitor< uint32_t > Monitoru
An unsigned 32bit integer monitor.
T operator|(const T &value) const
Monitor(const T &value)
Construct a new monitor with a given default 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.
Monitor< bool > Monitorb
A boolean monitor variable.
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.
LUNCHBOX_API void broadcast()
Broadcast the condition.
LUNCHBOX_API void wait()
Atomically unlock the mutex, wait for a signal and relock the mutex.
bool timedWaitEQ(const T &value, const uint32_t timeout) const
Block until the monitor has the given value.
void set(const T &value)
Set a new value.
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array.
Monitor & operator++()
Increment the monitored value, prefix only.
T operator+(const T &value) const
~Monitor()
Destructs the monitor.