41 #ifndef CRL_MULTISENSE_THREAD_HH
42 #define CRL_MULTISENSE_THREAD_HH
44 #ifndef WIN32_LEAN_AND_MEAN
45 #define WIN32_LEAN_AND_MEAN 1
78 Thread(LPTHREAD_START_ROUTINE functionP,
82 int32_t priority=0) :
m_flags(flags) {
87 if (-1 != scheduler) {
118 CRL_DEBUG(
"WaitForSingleObject() failed: %d\n", GetLastError());
136 InitializeCriticalSection(&
m_mutex);
140 DeleteCriticalSection(&
m_mutex);
155 this->
lock(&mutex.m_mutex);
172 void lock(CRITICAL_SECTION *lockP) {
194 if (0 ==
wait_(INFINITE))
208 int32_t ret =
wait_((DWORD)(timeout * 1000));
212 else if (ETIMEDOUT == ret)
224 return ReleaseSemaphore(
m_handle, 1, NULL) != FALSE;
234 while(WaitForSingleObject (
m_handle, 0) == WAIT_OBJECT_0)
247 m_handle = CreateSemaphore (NULL, 0, (max == 0 || max > LONG_MAX) ? LONG_MAX : max, NULL);
249 CRL_EXCEPTION (
"CreateSemaphore() failed: %d\n", GetLastError());
264 inline int32_t
wait_(DWORD ts=INFINITE) {
266 const int32_t ret = WaitForSingleObject (
m_handle, ts);
269 if (ret == WAIT_OBJECT_0)
271 else if (ret == WAIT_TIMEOUT)
284 template<
class T>
class WaitVar {
305 const double& timeout) {
334 template <
class T>
class WaitQueue {