X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3ad41c280f8d84a34b20e29719fea73481386840..e6ba38871f6cc5c02391c04e37e481d0428cef3f:/src/msw/thread.cpp diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 072df5b373..cc4d13a2e6 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -189,12 +189,15 @@ private: wxMutexError LockTimeout(DWORD milliseconds); HANDLE m_mutex; + + unsigned long m_owningThread; + wxMutexType m_type; DECLARE_NO_COPY_CLASS(wxMutexInternal) }; // all mutexes are recursive under Win32 so we don't use mutexType -wxMutexInternal::wxMutexInternal(wxMutexType WXUNUSED(mutexType)) +wxMutexInternal::wxMutexInternal(wxMutexType mutexType) { // create a nameless (hence intra process and always private) mutex m_mutex = ::CreateMutex @@ -204,10 +207,14 @@ wxMutexInternal::wxMutexInternal(wxMutexType WXUNUSED(mutexType)) NULL // no name ); + m_type = mutexType; + m_owningThread = 0; + if ( !m_mutex ) { wxLogLastError(_T("CreateMutex()")); } + } wxMutexInternal::~wxMutexInternal() @@ -231,6 +238,16 @@ wxMutexError wxMutexInternal::TryLock() wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds) { + if (m_type == wxMUTEX_DEFAULT) + { + // Don't allow recursive + if (m_owningThread != 0) + { + if (m_owningThread == wxThread::GetCurrentId()) + return wxMUTEX_DEAD_LOCK; + } + } + DWORD rc = ::WaitForSingleObject(m_mutex, milliseconds); if ( rc == WAIT_ABANDONED ) { @@ -261,11 +278,20 @@ wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds) return wxMUTEX_MISC_ERROR; } + if (m_type == wxMUTEX_DEFAULT) + { + // required for checking recursiveness + 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()"));