#if wxUSE_THREADS
#include "wx/thread.h"
+#include "wx/except.h"
#ifndef WX_PRECOMP
+ #include "wx/app.h"
#include "wx/dynarray.h"
#include "wx/intl.h"
#include "wx/log.h"
private:
pthread_mutex_t m_mutex;
bool m_isOk;
+ wxMutexType m_type;
+ unsigned long m_owningThread;
// wxConditionInternal uses our m_mutex
friend class wxConditionInternal;
wxMutexInternal::wxMutexInternal(wxMutexType mutexType)
{
+ m_type = mutexType;
+ m_owningThread = 0;
+
int err;
switch ( mutexType )
{
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));
}
wxMutexError wxMutexInternal::HandleLockResult(int err)
{
+ // wxPrintf( "err %d\n", err );
+
switch ( err )
{
case EDEADLK:
return wxMUTEX_TIMEOUT;
case 0:
+ if (m_type == wxMUTEX_DEFAULT)
+ m_owningThread = wxThread::GetCurrentId();
return wxMUTEX_NO_ERROR;
default:
break;
case 0:
+ if (m_type == wxMUTEX_DEFAULT)
+ m_owningThread = wxThread::GetCurrentId();
return wxMUTEX_NO_ERROR;
default:
wxMutexError wxMutexInternal::Unlock()
{
+ m_owningThread = 0;
+
int err = pthread_mutex_unlock(&m_mutex);
switch ( err )
{
_T("Thread %ld about to enter its Entry()."),
THR_ID(pthread));
- pthread->m_exitcode = thread->Entry();
+ wxTRY
+ {
+ pthread->m_exitcode = thread->Entry();
- wxLogTrace(TRACE_THREADS,
- _T("Thread %ld Entry() returned %lu."),
- THR_ID(pthread), wxPtrToUInt(pthread->m_exitcode));
+ wxLogTrace(TRACE_THREADS,
+ _T("Thread %ld Entry() returned %lu."),
+ THR_ID(pthread), wxPtrToUInt(pthread->m_exitcode));
+ }
+ wxCATCH_ALL( wxTheApp->OnUnhandledException(); )
{
wxCriticalSectionLocker lock(thread->m_critsect);
#endif
}
-void wxThread::Sleep(unsigned long milliseconds)
-{
- wxMilliSleep(milliseconds);
-}
-
int wxThread::GetCPUCount()
{
#if defined(_SC_NPROCESSORS_ONLN)
// might deadlock if, for example, it signals a condition in OnExit() (a
// common case) while the main thread calls any of functions entering
// m_critsect on us (almost all of them do)
- OnExit();
+ wxTRY
+ {
+ OnExit();
+ }
+ wxCATCH_ALL( wxTheApp->OnUnhandledException(); )
// delete C++ thread object if this is a detached thread - user is
// responsible for doing this for joinable ones
}
}
-void wxMutexGuiEnter()
+void wxMutexGuiEnterImpl()
{
gs_mutexGui->Lock();
}
-void wxMutexGuiLeave()
+void wxMutexGuiLeaveImpl()
{
gs_mutexGui->Unlock();
}