42 #ifndef CRL_MULTISENSE_THREAD_HH
43 #define CRL_MULTISENSE_THREAD_HH
45 #ifndef WIN32_LEAN_AND_MEAN
46 #define WIN32_LEAN_AND_MEAN 1
79 Thread(LPTHREAD_START_ROUTINE functionP,
83 int32_t priority=0) :
m_flags(flags) {
88 if (-1 != scheduler) {
119 CRL_DEBUG(
"WaitForSingleObject() failed: %d\n", (
int)GetLastError());
137 InitializeCriticalSection(&
m_mutex);
141 DeleteCriticalSection(&
m_mutex);
173 void lock(CRITICAL_SECTION *lockP) {
195 if (0 ==
wait_(INFINITE))
209 int32_t ret =
wait_((DWORD)(timeout * 1000));
213 else if (ETIMEDOUT == ret)
225 return ReleaseSemaphore(
m_handle, 1, NULL) != FALSE;
235 while(WaitForSingleObject (
m_handle, 0) == WAIT_OBJECT_0)
248 m_handle = CreateSemaphore (NULL, 0, (max == 0 || max > LONG_MAX) ? LONG_MAX : max, NULL);
250 CRL_EXCEPTION (
"CreateSemaphore() failed: %d\n", GetLastError());
265 inline int32_t
wait_(DWORD ts=INFINITE) {
267 const int32_t ret = WaitForSingleObject (
m_handle, ts);
270 if (ret == WAIT_OBJECT_0)
272 else if (ret == WAIT_TIMEOUT)
285 template<
class T>
class WaitVar {
306 const double& timeout) {
335 template <
class T>
class WaitQueue {