#ifndef __WAITVARIABLE_H__ #define __WAITVARIABLE_H__ #include "util/boostthread.h" #ifdef _WIN32_WCE // for some strange reason 'clock' is not in wince. namespace std { #define CLOCKS_PER_SEC 1000 inline clock_t clock() { return GetTickCount(); } } #endif #include //#include // this implements a variable, which can be set in one thread, // and waited for a specific value in another thread. template class waitvariable { private: boost::condition _cond; boost::mutex _mtx; T _value; bool _changed; public: waitvariable(T initial) : _value(initial), _changed(false) { } // wait until the waitvar is equal to the specified value bool wait_equal(T value, double timeout=-1) { boost::mutex::scoped_lock lock(_mtx); boost::timer t0; while (value!=_value && (timeout<0 || t0.elapsed() s, double timeout=-1) { boost::mutex::scoped_lock lock(_mtx); boost::timer t0; while (s.find(_value)==s.end() && (timeout<0 || t0.elapsed() s, double timeout=-1) { boost::mutex::scoped_lock lock(_mtx); boost::timer t0; while (s.find(_value)!=s.end() && (timeout<0 || t0.elapsed() T wait_until(P pred, double timeout=-1) { boost::mutex::scoped_lock lock(_mtx); boost::timer t0; while (!pred(_value) && (timeout<0 || t0.elapsed()