X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be8098689121d2352751c51005c133797d77ecea..2d956b58023a4955313a1c1531bc70a0deb0b831:/src/unix/threadpsx.cpp diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index 4524bae5b8..72be919335 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -319,7 +319,7 @@ wxMutexError wxMutex::Unlock() class wxConditionInternal { public: - wxConditionInternal( wxMutex *mutex ); + wxConditionInternal(wxMutex& mutex); ~wxConditionInternal(); void Wait(); @@ -331,14 +331,16 @@ public: 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")); @@ -355,7 +357,7 @@ wxConditionInternal::~wxConditionInternal() 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")); } @@ -363,13 +365,14 @@ void wxConditionInternal::Wait() 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; } @@ -397,18 +400,9 @@ void wxConditionInternal::Broadcast() // 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() @@ -418,14 +412,11 @@ 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; @@ -444,14 +435,12 @@ bool wxCondition::Wait( unsigned long 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(); } // =========================================================================== @@ -497,11 +486,11 @@ wxSemaphoreInternal::wxSemaphoreInternal( int initialcount, int maxcount ) void wxSemaphoreInternal::Wait() { - wxMutexLocker locker(*m_mutex); + wxMutexLocker locker(m_mutex); while ( count <= 0 ) { - m_cond->Wait(); + m_cond.Wait(); } count--; @@ -509,7 +498,7 @@ void wxSemaphoreInternal::Wait() bool wxSemaphoreInternal::TryWait() { - wxMutexLocker locker(*m_mutex); + wxMutexLocker locker(m_mutex); if ( count <= 0 ) return FALSE; @@ -521,7 +510,7 @@ bool wxSemaphoreInternal::TryWait() bool wxSemaphoreInternal::Wait( unsigned long timeout_millis ) { - wxMutexLocker locker( *m_mutex ); + wxMutexLocker locker(m_mutex); wxLongLong startTime = wxGetLocalTimeMillis(); @@ -532,7 +521,7 @@ bool wxSemaphoreInternal::Wait( unsigned long timeout_millis ) if ( remainingTime <= 0 ) return FALSE; - bool result = m_cond->Wait( remainingTime ); + bool result = m_cond.Wait( remainingTime ); if ( !result ) return FALSE; } @@ -544,16 +533,16 @@ bool wxSemaphoreInternal::Wait( unsigned long timeout_millis ) 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(); } // -------------------------------------------------------------------------- @@ -602,7 +591,7 @@ public: m_signaled = FALSE; m_mutex = new wxMutex(); - m_cond = new wxCondition( m_mutex ); + m_cond = new wxCondition( *m_mutex ); } // increment the reference count @@ -1711,7 +1700,7 @@ bool wxThreadModule::OnInit() #endif // wxUSE_GUI gs_mutexDeleteThread = new wxMutex(); - gs_condAllDeleted = new wxCondition( gs_mutexDeleteThread ); + gs_condAllDeleted = new wxCondition( *gs_mutexDeleteThread ); return TRUE; }