X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0eb949e11fc9ef4aa72c072ba9d1025ed08ce199..69fb2f97492421b85b661add445012e98c1eaea9:/src/unix/threadpsx.cpp diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index a133ba9fa0..692be7d169 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -67,17 +67,6 @@ #define THR_ID(thr) ((long)(thr)->GetId()) #endif -#ifdef __WXMAC__ - - // implement wxCriticalSection using mutexes -wxCriticalSection::wxCriticalSection( wxCriticalSectionType critSecType ) - : m_mutex( critSecType == wxCRITSEC_DEFAULT ? wxMUTEX_RECURSIVE : wxMUTEX_DEFAULT ) { } -wxCriticalSection::~wxCriticalSection() { } - -void wxCriticalSection::Enter() { (void)m_mutex.Lock(); } -void wxCriticalSection::Leave() { (void)m_mutex.Unlock(); } - -#endif // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -189,6 +178,8 @@ private: private: pthread_mutex_t m_mutex; bool m_isOk; + wxMutexType m_type; + unsigned long m_owningThread; // wxConditionInternal uses our m_mutex friend class wxConditionInternal; @@ -203,6 +194,9 @@ extern "C" int pthread_mutexattr_settype(pthread_mutexattr_t *, int); wxMutexInternal::wxMutexInternal(wxMutexType mutexType) { + m_type = mutexType; + m_owningThread = 0; + int err; switch ( mutexType ) { @@ -263,6 +257,12 @@ wxMutexInternal::~wxMutexInternal() wxMutexError wxMutexInternal::Lock() { + if ((m_type == wxMUTEX_DEFAULT) && (m_owningThread != 0)) + { + if (m_owningThread == wxThread::GetCurrentId()) + return wxMUTEX_DEAD_LOCK; + } + return HandleLockResult(pthread_mutex_lock(&m_mutex)); } @@ -318,6 +318,8 @@ wxMutexError wxMutexInternal::Lock(unsigned long ms) wxMutexError wxMutexInternal::HandleLockResult(int err) { + // wxPrintf( "err %d\n", err ); + switch ( err ) { case EDEADLK: @@ -334,6 +336,8 @@ wxMutexError wxMutexInternal::HandleLockResult(int err) return wxMUTEX_TIMEOUT; case 0: + if (m_type == wxMUTEX_DEFAULT) + m_owningThread = wxThread::GetCurrentId(); return wxMUTEX_NO_ERROR; default: @@ -359,6 +363,8 @@ wxMutexError wxMutexInternal::TryLock() break; case 0: + if (m_type == wxMUTEX_DEFAULT) + m_owningThread = wxThread::GetCurrentId(); return wxMUTEX_NO_ERROR; default: @@ -370,6 +376,8 @@ wxMutexError wxMutexInternal::TryLock() wxMutexError wxMutexInternal::Unlock() { + m_owningThread = 0; + int err = pthread_mutex_unlock(&m_mutex); switch ( err ) {