57 Event(
bool isAutoReset =
true,
bool isSignal =
false)
61 : _is_signalled(isSignal), _isAutoReset(isAutoReset)
69 pthread_mutex_init(&_cond_locker,
nullptr);
70 pthread_cond_init(&_cond_var,
nullptr);
75 void set(
bool isSignal =
true)
82 pthread_mutex_lock(&_cond_locker);
84 if (_is_signalled ==
false)
87 pthread_cond_signal(&_cond_var);
89 pthread_mutex_unlock(&_cond_locker);
97 pthread_mutex_lock(&_cond_locker);
98 _is_signalled =
false;
99 pthread_mutex_unlock(&_cond_locker);
104 unsigned long wait(
unsigned long timeout = 0xFFFFFFFF)
107 switch (WaitForSingleObject(
108 _event, timeout == 0xFFFFFFF ? INFINITE : (DWORD)timeout))
120 pthread_mutex_lock(&_cond_locker);
124 if (timeout == 0xFFFFFFFF)
126 pthread_cond_wait(&_cond_var, &_cond_locker);
132 gettimeofday(&
now,
nullptr);
134 wait_time.tv_sec = timeout / 1000 +
now.tv_sec;
136 (timeout % 1000) * 1000000ULL +
now.tv_usec * 1000;
138 if (wait_time.tv_nsec >= 1000000000)
141 wait_time.tv_nsec -= 1000000000;
143 switch (pthread_cond_timedwait(
144 &_cond_var, &_cond_locker, &wait_time))
161 assert(_is_signalled);
165 _is_signalled =
false;
168 pthread_mutex_unlock(&_cond_locker);
180 pthread_mutex_destroy(&_cond_locker);
181 pthread_cond_destroy(&_cond_var);
188 pthread_cond_t _cond_var;
189 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)