X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ee4f8c2af9c6c5458e488db10aef7d00a89ace25..d93f63db9d836a7d303343e60fb034dc9a1360d0:/src/gtk1/threadpsx.cpp?ds=sidebyside diff --git a/src/gtk1/threadpsx.cpp b/src/gtk1/threadpsx.cpp index ce5396c6d7..363f0636ea 100644 --- a/src/gtk1/threadpsx.cpp +++ b/src/gtk1/threadpsx.cpp @@ -14,8 +14,11 @@ #include #include -#include #include +#include +#include "wx/thread.h" +#include "wx/module.h" +#include "wx/utils.h" enum thread_state { STATE_IDLE = 0, @@ -28,8 +31,6 @@ enum thread_state { // Static variables ///////////////////////////////////////////////////////////////////////////// -#include "thread.h" - static pthread_t p_mainid; wxMutex wxMainMutex; // controls access to all GUI functions @@ -51,13 +52,15 @@ wxMutex::wxMutex() { p_internal = new wxMutexInternal; pthread_mutex_init(&(p_internal->p_mutex), NULL); - m_locked = false; + m_locked = 0; } wxMutex::~wxMutex() { - if (m_locked) - pthread_mutex_unlock(&(p_internal->p_mutex)); + if (m_locked > 0) + wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n", + m_locked); + pthread_mutex_destroy(&(p_internal->p_mutex)); delete p_internal; } @@ -67,9 +70,8 @@ wxMutexError wxMutex::Lock() int err; err = pthread_mutex_lock(&(p_internal->p_mutex)); - switch (err) { - case EDEADLK: return MUTEX_DEAD_LOCK; - } + if (err == EDEADLK) + return MUTEX_DEAD_LOCK; m_locked++; return MUTEX_NO_ERROR; } @@ -90,7 +92,10 @@ wxMutexError wxMutex::TryLock() wxMutexError wxMutex::Unlock() { - if (m_locked > 0) m_locked--; + if (m_locked > 0) + m_locked--; + else + return MUTEX_UNLOCKED; pthread_mutex_unlock(&(p_internal->p_mutex)); return MUTEX_NO_ERROR; } @@ -274,7 +279,7 @@ void wxThread::TestDestroy() pthread_testcancel(); } -bool wxThread::IsMain() const +bool wxThread::IsMain() { return (bool)pthread_equal(pthread_self(), p_mainid); }