diff options
Diffstat (limited to 'src/uscxml/concurrency')
-rw-r--r-- | src/uscxml/concurrency/tinythread.cpp | 21 | ||||
-rw-r--r-- | src/uscxml/concurrency/tinythread.h | 4 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/uscxml/concurrency/tinythread.cpp b/src/uscxml/concurrency/tinythread.cpp index 6167545..d46cda3 100644 --- a/src/uscxml/concurrency/tinythread.cpp +++ b/src/uscxml/concurrency/tinythread.cpp @@ -85,10 +85,27 @@ condition_variable::~condition_variable() { #endif #if defined(_TTHREAD_WIN32_) -void condition_variable::_wait() { +void condition_variable::_wait(unsigned int ms) { + if (ms <= 0) + ms = INFINITE; // Wait for either event to become signaled due to notify_one() or // notify_all() being called - int result = WaitForMultipleObjects(2, mEvents, FALSE, INFINITE); + int result = WaitForMultipleObjects(2, mEvents, FALSE, ms); + if (result == WAIT_FAILED) { + LPVOID lpMsgBuf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, + 0, + NULL); +// UM_LOG_ERR("%s", lpMsgBuf); + LocalFree(lpMsgBuf); + + } // Check if we are the last waiter EnterCriticalSection(&mWaitersCountLock); diff --git a/src/uscxml/concurrency/tinythread.h b/src/uscxml/concurrency/tinythread.h index 9d211f4..867f036 100644 --- a/src/uscxml/concurrency/tinythread.h +++ b/src/uscxml/concurrency/tinythread.h @@ -421,7 +421,7 @@ public: // Release the mutex while waiting for the condition (will decrease // the number of waiters when done)... aMutex.unlock(); - _wait(); + _wait(0); aMutex.lock(); #else pthread_cond_wait(&mHandle, &aMutex.mHandle); @@ -483,7 +483,7 @@ public: private: #if defined(_TTHREAD_WIN32_) - void _wait(); + void _wait(unsigned int ms); HANDLE mEvents[2]; ///< Signal and broadcast event HANDLEs. unsigned int mWaitersCount; ///< Count of the number of waiters. CRITICAL_SECTION mWaitersCountLock; ///< Serialize access to mWaitersCount. |