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();
}
// ===========================================================================
};
wxSemaphoreInternal::wxSemaphoreInternal( int initialcount, int maxcount )
- : m_cond(&m_mutex)
+ : m_cond(m_mutex)
{
if ( (initialcount < 0) || ((maxcount > 0) && (initialcount > maxcount)) )
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;
}