X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be8098689121d2352751c51005c133797d77ecea..6cc687bfee071b5328f9e48d1708795287006bb7:/src/msw/thread.cpp diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index ec70911da4..e2c76f9389 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -354,8 +354,7 @@ void wxSemaphore::Post() class wxConditionInternal { public: - wxConditionInternal( wxMutex *mutex ); - ~wxConditionInternal(); + wxConditionInternal(wxMutex& mutex); void Wait(); @@ -369,22 +368,20 @@ private: int m_numWaiters; wxMutex m_mutexNumWaiters; - wxMutex *m_mutex; + wxMutex& m_mutex; wxSemaphore m_semaphore; + + DECLARE_NO_COPY_CLASS(wxConditionInternal) }; -wxConditionInternal::wxConditionInternal( wxMutex *mutex ) +wxConditionInternal::wxConditionInternal(wxMutex& mutex) + : m_mutex(mutex) { - m_mutex = mutex; m_numWaiters = 0; } -wxConditionInternal::~wxConditionInternal() -{ -} - void wxConditionInternal::Wait() { // increment the number of waiters @@ -392,7 +389,7 @@ void wxConditionInternal::Wait() m_numWaiters++; m_mutexNumWaiters.Unlock(); - m_mutex->Unlock(); + m_mutex.Unlock(); // a potential race condition can occur here // @@ -407,7 +404,7 @@ void wxConditionInternal::Wait() // wait ( if necessary ) and decrement semaphore m_semaphore.Wait(); - m_mutex->Lock(); + m_mutex.Lock(); } bool wxConditionInternal::Wait( unsigned long timeout_millis ) @@ -416,7 +413,7 @@ bool wxConditionInternal::Wait( unsigned long timeout_millis ) m_numWaiters++; m_mutexNumWaiters.Unlock(); - m_mutex->Unlock(); + m_mutex.Unlock(); // a race condition can occur at this point in the code // @@ -452,7 +449,7 @@ bool wxConditionInternal::Wait( unsigned long timeout_millis ) m_mutexNumWaiters.Unlock(); } - m_mutex->Lock(); + m_mutex.Lock(); return success; } @@ -489,18 +486,9 @@ void wxConditionInternal::Broadcast() // wxCondition implementation // ---------------------------------------------------------------------------- -wxCondition::wxCondition( wxMutex *mutex ) +wxCondition::wxCondition(wxMutex& mutex) { - if ( !mutex ) - { - wxFAIL_MSG( _T("NULL mutex in wxCondition ctor") ); - - m_internal = NULL; - } - else - { - m_internal = new wxConditionInternal( mutex ); - } + m_internal = new wxConditionInternal( mutex ); } wxCondition::~wxCondition() @@ -510,25 +498,22 @@ wxCondition::~wxCondition() void wxCondition::Wait() { - if ( m_internal ) - m_internal->Wait(); + m_internal->Wait(); } bool wxCondition::Wait( unsigned long timeout_millis ) { - return m_internal ? m_internal->Wait(timeout_millis) : FALSE; + return m_internal->Wait(timeout_millis); } void wxCondition::Signal() { - if ( m_internal ) - m_internal->Signal(); + m_internal->Signal(); } void wxCondition::Broadcast() { - if ( m_internal ) - m_internal->Broadcast(); + m_internal->Broadcast(); } // ---------------------------------------------------------------------------- @@ -1152,12 +1137,18 @@ wxThreadError wxThread::Delete(ExitCode *pRc) } } - if ( !::GetExitCodeThread(hThread, (LPDWORD)&rc) ) + // although the thread might be already in the EXITED state it might not + // have terminated yet and so we are not sure that it has actually + // terminated if the "if" above hadn't been taken + do { - wxLogLastError(wxT("GetExitCodeThread")); + if ( !::GetExitCodeThread(hThread, (LPDWORD)&rc) ) + { + wxLogLastError(wxT("GetExitCodeThread")); - rc = (ExitCode)-1; - } + rc = (ExitCode)-1; + } + } while ( (DWORD)rc == STILL_ACTIVE ); if ( IsDetached() ) { @@ -1168,9 +1159,6 @@ wxThreadError wxThread::Delete(ExitCode *pRc) delete this; } - wxASSERT_MSG( (DWORD)rc != STILL_ACTIVE, - wxT("thread must be already terminated.") ); - if ( pRc ) *pRc = rc;