36 namespace rp{
namespace hal{
49 Event(
bool isAutoReset =
true,
bool isSignal =
false)
53 : _is_signalled(isSignal)
54 , _isAutoReset(isAutoReset)
60 pthread_mutex_init(&_cond_locker, NULL);
61 pthread_cond_init(&_cond_var, NULL);
70 void set(
bool isSignal = true )
76 pthread_mutex_lock(&_cond_locker);
78 if ( _is_signalled ==
false )
81 pthread_cond_signal(&_cond_var);
83 pthread_mutex_unlock(&_cond_locker);
91 pthread_mutex_lock(&_cond_locker);
92 _is_signalled =
false;
93 pthread_mutex_unlock(&_cond_locker);
98 unsigned long wait(
unsigned long timeout = 0xFFFFFFFF )
101 switch (WaitForSingleObject(
_event, timeout==0xFFFFFFF?INFINITE:(DWORD)timeout))
113 pthread_mutex_lock( &_cond_locker );
115 if ( !_is_signalled )
118 if (timeout == 0xFFFFFFFF){
119 pthread_cond_wait(&_cond_var,&_cond_locker);
124 gettimeofday(&
now,NULL);
126 wait_time.tv_sec = timeout/1000 +
now.tv_sec;
127 wait_time.tv_nsec = (timeout%1000)*1000000ULL +
now.tv_usec*1000;
129 if (wait_time.tv_nsec >= 1000000000)
132 wait_time.tv_nsec -= 1000000000;
134 switch (pthread_cond_timedwait(&_cond_var,&_cond_locker,&wait_time))
152 assert(_is_signalled);
156 _is_signalled =
false;
159 pthread_mutex_unlock( &_cond_locker );
172 pthread_mutex_destroy(&_cond_locker);
173 pthread_cond_destroy(&_cond_var);
180 pthread_cond_t _cond_var;
181 pthread_mutex_t _cond_locker;
Event(bool isAutoReset=true, bool isSignal=false)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
unsigned long wait(unsigned long timeout=0xFFFFFFFF)