X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/424c9ce771d938db96d41135ba402a3a1134fa65..ccd5d46c7b69632eaa231e8fc7801dd5af2faaa8:/src/msw/thread.cpp diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index f6d9939eb4..2a692e374d 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -189,9 +189,8 @@ private: wxMutexError LockTimeout(DWORD milliseconds); HANDLE m_mutex; - + unsigned long m_owningThread; - bool m_isLocked; wxMutexType m_type; DECLARE_NO_COPY_CLASS(wxMutexInternal) @@ -210,13 +209,12 @@ wxMutexInternal::wxMutexInternal(wxMutexType mutexType) m_type = mutexType; m_owningThread = 0; - m_isLocked = false; if ( !m_mutex ) { wxLogLastError(_T("CreateMutex()")); } - + } wxMutexInternal::~wxMutexInternal() @@ -243,7 +241,7 @@ wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds) if (m_type == wxMUTEX_DEFAULT) { // Don't allow recursive - if (m_isLocked) + if (m_owningThread != 0) { if (m_owningThread == wxThread::GetCurrentId()) return wxMUTEX_DEAD_LOCK; @@ -251,18 +249,14 @@ wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds) } DWORD rc = ::WaitForSingleObject(m_mutex, milliseconds); - if ( rc == WAIT_ABANDONED ) - { - // the previous caller died without releasing the mutex, but now we can - // really lock it - wxLogDebug(_T("WaitForSingleObject() returned WAIT_ABANDONED")); - - // use 0 timeout, normally we should always get it - rc = ::WaitForSingleObject(m_mutex, 0); - } - switch ( rc ) { + case WAIT_ABANDONED: + // the previous caller died without releasing the mutex, so even + // though we did get it, log a message about this + wxLogDebug(_T("WaitForSingleObject() returned WAIT_ABANDONED")); + // fall through + case WAIT_OBJECT_0: // ok break; @@ -270,7 +264,6 @@ wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds) case WAIT_TIMEOUT: return wxMUTEX_TIMEOUT; - case WAIT_ABANDONED: // checked for above default: wxFAIL_MSG(wxT("impossible return value in wxMutex::Lock")); // fall through @@ -281,26 +274,25 @@ wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds) } if (m_type == wxMUTEX_DEFAULT) - { + { // required for checking recursiveness - m_isLocked = true; m_owningThread = wxThread::GetCurrentId(); } - + return wxMUTEX_NO_ERROR; } wxMutexError wxMutexInternal::Unlock() { + // required for checking recursiveness + m_owningThread = 0; + if ( !::ReleaseMutex(m_mutex) ) { wxLogLastError(_T("ReleaseMutex()")); return wxMUTEX_MISC_ERROR; } - - // required for checking recursiveness - m_isLocked = false; return wxMUTEX_NO_ERROR; }