47 Event(
bool isAutoReset =
true,
bool isSignal =
false)
51 : _is_signalled(isSignal), _isAutoReset(isAutoReset)
59 pthread_mutex_init(&_cond_locker,
nullptr);
60 pthread_cond_init(&_cond_var,
nullptr);
65 void set(
bool isSignal =
true)
72 pthread_mutex_lock(&_cond_locker);
74 if (_is_signalled ==
false)
77 pthread_cond_signal(&_cond_var);
79 pthread_mutex_unlock(&_cond_locker);
87 pthread_mutex_lock(&_cond_locker);
88 _is_signalled =
false;
89 pthread_mutex_unlock(&_cond_locker);
94 unsigned long wait(
unsigned long timeout = 0xFFFFFFFF)
97 switch (WaitForSingleObject(
98 _event, timeout == 0xFFFFFFF ? INFINITE : (DWORD)timeout))
110 pthread_mutex_lock(&_cond_locker);
114 if (timeout == 0xFFFFFFFF)
116 pthread_cond_wait(&_cond_var, &_cond_locker);
122 gettimeofday(&
now,
nullptr);
124 wait_time.tv_sec = timeout / 1000 +
now.tv_sec;
126 (timeout % 1000) * 1000000ULL +
now.tv_usec * 1000;
128 if (wait_time.tv_nsec >= 1000000000)
131 wait_time.tv_nsec -= 1000000000;
133 switch (pthread_cond_timedwait(
134 &_cond_var, &_cond_locker, &wait_time))
151 assert(_is_signalled);
155 _is_signalled =
false;
158 pthread_mutex_unlock(&_cond_locker);
170 pthread_mutex_destroy(&_cond_locker);
171 pthread_cond_destroy(&_cond_var);
178 pthread_cond_t _cond_var;
179 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)