fix handling of abandoned mutexes in wxMutex::Wait[Timeout]() (#10236)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57100 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -189,7 +189,7 @@ private:
|
|||||||
wxMutexError LockTimeout(DWORD milliseconds);
|
wxMutexError LockTimeout(DWORD milliseconds);
|
||||||
|
|
||||||
HANDLE m_mutex;
|
HANDLE m_mutex;
|
||||||
|
|
||||||
unsigned long m_owningThread;
|
unsigned long m_owningThread;
|
||||||
wxMutexType m_type;
|
wxMutexType m_type;
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ wxMutexInternal::wxMutexInternal(wxMutexType mutexType)
|
|||||||
{
|
{
|
||||||
wxLogLastError(_T("CreateMutex()"));
|
wxLogLastError(_T("CreateMutex()"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMutexInternal::~wxMutexInternal()
|
wxMutexInternal::~wxMutexInternal()
|
||||||
@@ -249,18 +249,14 @@ wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DWORD rc = ::WaitForSingleObject(m_mutex, 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 )
|
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:
|
case WAIT_OBJECT_0:
|
||||||
// ok
|
// ok
|
||||||
break;
|
break;
|
||||||
@@ -268,7 +264,6 @@ wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds)
|
|||||||
case WAIT_TIMEOUT:
|
case WAIT_TIMEOUT:
|
||||||
return wxMUTEX_TIMEOUT;
|
return wxMUTEX_TIMEOUT;
|
||||||
|
|
||||||
case WAIT_ABANDONED: // checked for above
|
|
||||||
default:
|
default:
|
||||||
wxFAIL_MSG(wxT("impossible return value in wxMutex::Lock"));
|
wxFAIL_MSG(wxT("impossible return value in wxMutex::Lock"));
|
||||||
// fall through
|
// fall through
|
||||||
@@ -279,11 +274,11 @@ wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_type == wxMUTEX_DEFAULT)
|
if (m_type == wxMUTEX_DEFAULT)
|
||||||
{
|
{
|
||||||
// required for checking recursiveness
|
// required for checking recursiveness
|
||||||
m_owningThread = wxThread::GetCurrentId();
|
m_owningThread = wxThread::GetCurrentId();
|
||||||
}
|
}
|
||||||
|
|
||||||
return wxMUTEX_NO_ERROR;
|
return wxMUTEX_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user