/// Thread conditional value
class BCondValue {
public:
BCondValue();
~BCondValue();
void setValue(int value); ///< Set the value. Wakes waiting
int value(); ///< Current value
int increment(int v = 1); ///< Increment. Wakes waiting
int decrement(int v = 1); ///< Decrement. Wakes waiting
int waitMoreThanOrEqual(int v, int decrement = 0, int timeOutUs = 0); ///< Wait until value is at least the value given
int waitLessThanOrEqual(int v, int increment = 0, int timeOutUs = 0); ///< Wait until value is equal to or below the value given
int waitLessThan(int v, int timeOutUs = 0); ///< Wait until value is equal to or below the value given
void operator+=(int v); ///< Add to value. Wakes waiting
void operator-=(int v); ///< Subtract from value. Wakes waiting
void operator++(int); ///< Increment value. Wakes waiting
void operator--(int); ///< Decrement value. Wakes waiting
private:
pthread_mutex_t omutex;
pthread_cond_t ocond;
int ovalue;
};
inline void BCondValue::operator+=(int v){
increment(v);
}
inline void BCondValue::operator-=(int v){
decrement(v);
}
inline void BCondValue::operator++(int){
increment(1);
}
inline void BCondValue::operator--(int){
decrement(1);
}
/// Thread conditional boolean
class BCondBool {
public:
BCondBool();
~BCondBool();
int set(); ///< Set value. Wakes waiting
int clear(); ///< Clear Value
int value(); ///< Current value
int wait(); ///< Wait until value is true
int timedWait(int timeOutUs); ///< Wait until set, with timeout