X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9111db680241332df07dd22db32973e20f77fb1a..849949b13fa19002da52333e760ebfecd00c60d9:/src/unix/threadpsx.cpp diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index a1764a30c3..eee36b4d3a 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -47,10 +47,6 @@ #include #endif -#ifdef __WXGTK12__ -#include "gtk/gtk.h" -#endif - // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -85,10 +81,8 @@ static pthread_t gs_tidMain; // the key for the pointer to the associated wxThread object static pthread_key_t gs_keySelf; -#ifndef __WXGTK12__ // this mutex must be acquired before any call to a GUI function static wxMutex *gs_mutexGui; -#endif // ============================================================================ // implementation @@ -107,7 +101,17 @@ public: wxMutex::wxMutex() { p_internal = new wxMutexInternal; + +#if 0 + /* I don't know where this function is supposed to exist, + and NP actually means non-portable, RR. */ + pthread_mutexattr_t attr_type; + pthread_mutexattr_settype( &attr_type, PTHREAD_MUTEX_FAST_NP ); + + pthread_mutex_init( &(p_internal->p_mutex), (const pthread_mutexattr_t*) &attr_type ); +#else pthread_mutex_init( &(p_internal->p_mutex), (const pthread_mutexattr_t*) NULL ); +#endif m_locked = 0; } @@ -277,6 +281,8 @@ private: // state // 2. The Delete() function blocks until the condition is signaled when the // thread exits. + // GL: On Linux, this may fail because we can have a deadlock in either + // SignalExit() or Wait(): so we add m_end_mutex for the finalization. wxMutex m_mutex, m_end_mutex; wxCondition m_cond; @@ -305,7 +311,7 @@ void *wxThreadInternal::PthreadStart(void *ptr) } #if HAVE_THREAD_CLEANUP_FUNCTIONS // Install the cleanup handler. -// pthread_cleanup_push(wxThreadInternal::PthreadCleanup, ptr); + pthread_cleanup_push(wxThreadInternal::PthreadCleanup, ptr); #endif // wait for the condition to be signaled from Run() @@ -317,7 +323,7 @@ void *wxThreadInternal::PthreadStart(void *ptr) status = thread->Entry(); #if HAVE_THREAD_CLEANUP_FUNCTIONS -// pthread_cleanup_pop(FALSE); + pthread_cleanup_pop(FALSE); #endif // terminate the thread @@ -377,8 +383,16 @@ wxThreadInternal::~wxThreadInternal() // note that m_mutex will be unlocked by the thread which waits for our // termination - // m_end_mutex can be unlocked here. - m_end_mutex.Unlock(); + // In the case, we didn't start the thread, all these mutex are locked: + // we must unlock them. + if (m_mutex.IsLocked()) + m_mutex.Unlock(); + + if (m_end_mutex.IsLocked()) + m_end_mutex.Unlock(); + + if (m_mutexSuspend.IsLocked()) + m_mutexSuspend.Unlock(); } wxThreadError wxThreadInternal::Run() @@ -664,6 +678,9 @@ wxThreadError wxThread::Resume() wxThread::ExitCode wxThread::Delete() { + if (IsPaused()) + Resume(); + m_critsect.Enter(); wxThreadState state = p_internal->GetState(); @@ -689,6 +706,8 @@ wxThread::ExitCode wxThread::Delete() // wait until the thread stops p_internal->Wait(); } + //GL: As we must auto-destroy, the destruction must happen here. + delete this; return NULL; } @@ -710,6 +729,8 @@ wxThreadError wxThread::Kill() return wxTHREAD_MISC_ERROR; } + //GL: As we must auto-destroy, the destruction must happen here (2). + delete this; return wxTHREAD_NO_ERROR; } @@ -754,6 +775,14 @@ bool wxThread::TestDestroy() wxThread::~wxThread() { + m_critsect.Enter(); + if (p_internal->GetState() != STATE_EXITED && + p_internal->GetState() != STATE_NEW) + wxLogDebug(_T("The thread is being destroyed althought it is still running ! The application may crash.")); + + m_critsect.Leave(); + + delete p_internal; // remove this thread from the global array gs_allThreads.Remove(this); } @@ -818,15 +847,11 @@ bool wxThreadModule::OnInit() return FALSE; } -#ifndef __WXGTK12__ gs_mutexGui = new wxMutex(); -#endif gs_tidMain = pthread_self(); -#ifndef __WXGTK12__ gs_mutexGui->Lock(); -#endif return TRUE; } @@ -845,12 +870,10 @@ void wxThreadModule::OnExit() gs_allThreads[n]->Delete(); } -#ifndef __WXGTK12__ // destroy GUI mutex gs_mutexGui->Unlock(); delete gs_mutexGui; -#endif // and free TLD slot (void)pthread_key_delete(gs_keySelf); @@ -862,20 +885,12 @@ void wxThreadModule::OnExit() void wxMutexGuiEnter() { -#ifdef __WXGTK12__ - gdk_threads_enter(); -#else gs_mutexGui->Lock(); -#endif } void wxMutexGuiLeave() { -#ifdef __WXGTK12__ - gdk_threads_leave(); -#else gs_mutexGui->Unlock(); -#endif } #endif