class wxConditionInternal
{
public:
- wxConditionInternal( wxMutex *mutex );
- ~wxConditionInternal();
+ wxConditionInternal(wxMutex& mutex);
void Wait();
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
m_numWaiters++;
m_mutexNumWaiters.Unlock();
- m_mutex->Unlock();
+ m_mutex.Unlock();
// a potential race condition can occur here
//
// wait ( if necessary ) and decrement semaphore
m_semaphore.Wait();
- m_mutex->Lock();
+ m_mutex.Lock();
}
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
//
m_mutexNumWaiters.Unlock();
}
- m_mutex->Lock();
+ m_mutex.Lock();
return success;
}
// 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()
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();
}
// ----------------------------------------------------------------------------
}
}
- 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() )
{
delete this;
}
- wxASSERT_MSG( (DWORD)rc != STILL_ACTIVE,
- wxT("thread must be already terminated.") );
-
if ( pRc )
*pRc = rc;