49 Event(
bool isAutoReset =
true,
bool isSignal =
false)
53 : _is_signalled(isSignal), _isAutoReset(isAutoReset)
61 pthread_mutex_init(&_cond_locker,
nullptr);
62 pthread_cond_init(&_cond_var,
nullptr);
67 void set(
bool isSignal =
true)
74 pthread_mutex_lock(&_cond_locker);
76 if (_is_signalled ==
false)
79 pthread_cond_signal(&_cond_var);
81 pthread_mutex_unlock(&_cond_locker);
89 pthread_mutex_lock(&_cond_locker);
90 _is_signalled =
false;
91 pthread_mutex_unlock(&_cond_locker);
96 unsigned long wait(
unsigned long timeout = 0xFFFFFFFF)
99 switch (WaitForSingleObject(
100 _event, timeout == 0xFFFFFFF ? INFINITE : (DWORD)timeout))
112 pthread_mutex_lock(&_cond_locker);
116 if (timeout == 0xFFFFFFFF)
118 pthread_cond_wait(&_cond_var, &_cond_locker);
124 gettimeofday(&
now,
nullptr);
126 wait_time.tv_sec = timeout / 1000 +
now.tv_sec;
128 (timeout % 1000) * 1000000ULL +
now.tv_usec * 1000;
130 if (wait_time.tv_nsec >= 1000000000)
133 wait_time.tv_nsec -= 1000000000;
135 switch (pthread_cond_timedwait(
136 &_cond_var, &_cond_locker, &wait_time))
153 assert(_is_signalled);
157 _is_signalled =
false;
160 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)