X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..a38b83c353cce75329b2c53c0eaa4ad0f500ccf1:/src/msw/thread.cpp diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index f6b625878f..a592fbf29e 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -13,6 +13,9 @@ #pragma implementation "thread.h" #endif +// this is here to regen the precompiled header in the ide compile otherwise the +// compiler crashes in vc5 (nfi why) +// For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #if defined(__BORLANDC__) @@ -41,7 +44,7 @@ enum thread_state { ///////////////////////////////////////////////////////////////////////////// static HANDLE p_mainid; -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions ///////////////////////////////////////////////////////////////////////////// // Windows implementation @@ -52,19 +55,21 @@ public: HANDLE p_mutex; }; -wxMutex::wxMutex(void) +wxMutex::wxMutex() { p_internal = new wxMutexInternal; p_internal->p_mutex = CreateMutex(NULL, FALSE, NULL); m_locked = 0; } -wxMutex::~wxMutex(void) +wxMutex::~wxMutex() { + if (m_locked > 0) + wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked); CloseHandle(p_internal->p_mutex); } -wxMutexError wxMutex::Lock(void) +wxMutexError wxMutex::Lock() { DWORD ret; @@ -76,7 +81,7 @@ wxMutexError wxMutex::Lock(void) return MUTEX_NO_ERROR; } -wxMutexError wxMutex::TryLock(void) +wxMutexError wxMutex::TryLock() { DWORD ret; @@ -88,7 +93,7 @@ wxMutexError wxMutex::TryLock(void) return MUTEX_NO_ERROR; } -wxMutexError wxMutex::Unlock(void) +wxMutexError wxMutex::Unlock() { BOOL ret; @@ -107,14 +112,14 @@ public: int waiters; }; -wxCondition::wxCondition(void) +wxCondition::wxCondition() { p_internal = new wxConditionInternal; p_internal->event = CreateEvent(NULL, FALSE, FALSE, NULL); p_internal->waiters = 0; } -wxCondition::~wxCondition(void) +wxCondition::~wxCondition() { CloseHandle(p_internal->event); } @@ -142,12 +147,12 @@ bool wxCondition::Wait(wxMutex& mutex, unsigned long sec, return (ret != WAIT_TIMEOUT); } -void wxCondition::Signal(void) +void wxCondition::Signal() { SetEvent(p_internal->event); } -void wxCondition::Broadcast(void) +void wxCondition::Broadcast() { int i; @@ -176,7 +181,7 @@ DWORD wxThreadInternal::WinThreadStart(LPVOID arg) return ret; } -wxThreadError wxThread::Create(void) +wxThreadError wxThread::Create() { int win_prio, prio = p_internal->prio; @@ -231,7 +236,7 @@ void wxThread::SetPriority(int prio) p_internal->prio = prio; } -int wxThread::GetPriority(void) +int wxThread::GetPriority() const { return p_internal->prio; } @@ -255,10 +260,10 @@ void *wxThread::Join() return NULL; if (wxThread::IsMain()) - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); WaitForSingleObject(p_internal->thread_id, INFINITE); if (wxThread::IsMain()) - wxMainMutex.Lock(); + wxMainMutex->Lock(); GetExitCodeThread(p_internal->thread_id, &exit_code); CloseHandle(p_internal->thread_id); @@ -268,7 +273,7 @@ void *wxThread::Join() return (void *)exit_code; } -unsigned long wxThread::GetID() +unsigned long wxThread::GetID() const { return (unsigned long)p_internal->tid; } @@ -304,15 +309,17 @@ void wxThread::OnExit() class wxThreadModule : public wxModule { DECLARE_DYNAMIC_CLASS(wxThreadModule) public: - virtual bool OnInit(void) { + virtual bool OnInit() { + wxMainMutex = new wxMutex(); p_mainid = GetCurrentThread(); - wxMainMutex.Lock(); + wxMainMutex->Lock(); return TRUE; } // Global cleanup - virtual void OnExit(void) { - wxMainMutex.Unlock(); + virtual void OnExit() { + wxMainMutex->Unlock(); + delete wxMainMutex; } };