class wxConditionInternal
{
public:
- wxConditionInternal( wxMutex *mutex );
+ wxConditionInternal(wxMutex& mutex);
~wxConditionInternal();
void Wait();
void Broadcast();
private:
+ // get the POSIX mutex associated with us
+ pthread_mutex_t *GetMutex() const { return &m_mutex.m_internal->m_mutex; }
- wxMutex *m_mutex;
+ wxMutex& m_mutex;
pthread_cond_t m_cond;
};
-wxConditionInternal::wxConditionInternal( wxMutex *mutex )
+wxConditionInternal::wxConditionInternal(wxMutex& mutex)
+ : m_mutex(mutex)
{
- m_mutex = mutex;
if ( pthread_cond_init( &m_cond, NULL ) != 0 )
{
wxLogDebug(_T("pthread_cond_init() failed"));
void wxConditionInternal::Wait()
{
- if ( pthread_cond_wait( &m_cond, &(m_mutex->m_internal->m_mutex) ) != 0 )
+ if ( pthread_cond_wait( &m_cond, GetMutex() ) != 0 )
{
wxLogDebug(_T("pthread_cond_wait() failed"));
}
bool wxConditionInternal::Wait( const timespec *ts )
{
- int result = pthread_cond_timedwait( &m_cond,
- &(m_mutex->m_internal->m_mutex),
- ts );
+ int result = pthread_cond_timedwait( &m_cond, GetMutex(), ts );
if ( result == ETIMEDOUT )
return FALSE;
- wxASSERT_MSG( result == 0, _T("pthread_cond_timedwait() failed") );
+ if ( result != 0 )
+ {
+ wxLogDebug(_T("pthread_cond_timedwait() failed"));
+ }
return TRUE;
}
// wxCondition
// ---------------------------------------------------------------------------
-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 )
{
- wxCHECK_MSG( m_internal, FALSE, _T("can't wait on uninitalized condition") );
-
wxLongLong curtime = wxGetLocalTimeMillis();
curtime += timeout_millis;
wxLongLong temp = curtime / 1000;
void wxCondition::Signal()
{
- if ( m_internal )
- m_internal->Signal();
+ m_internal->Signal();
}
void wxCondition::Broadcast()
{
- if ( m_internal )
- m_internal->Broadcast();
+ m_internal->Broadcast();
}
// ===========================================================================
void wxSemaphoreInternal::Wait()
{
- wxMutexLocker locker(*m_mutex);
+ wxMutexLocker locker(m_mutex);
while ( count <= 0 )
{
- m_cond->Wait();
+ m_cond.Wait();
}
count--;
bool wxSemaphoreInternal::TryWait()
{
- wxMutexLocker locker(*m_mutex);
+ wxMutexLocker locker(m_mutex);
if ( count <= 0 )
return FALSE;
bool wxSemaphoreInternal::Wait( unsigned long timeout_millis )
{
- wxMutexLocker locker( *m_mutex );
+ wxMutexLocker locker(m_mutex);
wxLongLong startTime = wxGetLocalTimeMillis();
if ( remainingTime <= 0 )
return FALSE;
- bool result = m_cond->Wait( remainingTime );
+ bool result = m_cond.Wait( remainingTime );
if ( !result )
return FALSE;
}
void wxSemaphoreInternal::Post()
{
- wxMutexLocker locker(*m_mutex);
+ wxMutexLocker locker(m_mutex);
- if ( (maxcount > 0) && (count == maxcount) )
+ if ( maxcount > 0 && count == maxcount )
{
wxFAIL_MSG( _T("wxSemaphore::Post() overflow") );
}
count++;
- m_cond->Signal();
+ m_cond.Signal();
}
// --------------------------------------------------------------------------
m_signaled = FALSE;
m_mutex = new wxMutex();
- m_cond = new wxCondition( m_mutex );
+ m_cond = new wxCondition( *m_mutex );
}
// increment the reference count
#endif // wxUSE_GUI
gs_mutexDeleteThread = new wxMutex();
- gs_condAllDeleted = new wxCondition( gs_mutexDeleteThread );
+ gs_condAllDeleted = new wxCondition( *gs_mutexDeleteThread );
return TRUE;
}