+wxMutexInternal::~wxMutexInternal()
+{
+ if ( m_isOk )
+ {
+ int err = pthread_mutex_destroy( &m_mutex );
+ if ( err != 0 )
+ {
+ wxLogApiError( wxT("pthread_mutex_destroy()"), err );
+ }
+ }
+}
+
+wxMutexError wxMutexInternal::Lock()
+{
+ int err = pthread_mutex_lock( &m_mutex );
+ switch ( err )
+ {
+ case EDEADLK:
+ // only error checking mutexes return this value and so it's an
+ // unexpected situation -- hence use assert, not wxLogDebug
+ wxFAIL_MSG( wxT("mutex deadlock prevented") );
+ return wxMUTEX_DEAD_LOCK;
+
+ case EINVAL:
+ wxLogDebug( wxT("pthread_mutex_lock(): mutex not initialized.") );
+ break;
+
+ case 0:
+ return wxMUTEX_NO_ERROR;
+
+ default:
+ wxLogApiError( wxT("pthread_mutex_lock()"), err );
+ }
+
+ return wxMUTEX_MISC_ERROR;
+}
+
+wxMutexError wxMutexInternal::TryLock()
+{
+ int err = pthread_mutex_trylock( &m_mutex );
+ switch ( err )
+ {
+ case EBUSY:
+ // not an error: mutex is already locked, but we're prepared for this case
+ return wxMUTEX_BUSY;
+
+ case EINVAL:
+ wxLogDebug( wxT("pthread_mutex_trylock(): mutex not initialized.") );
+ break;
+
+ case 0:
+ return wxMUTEX_NO_ERROR;
+
+ default:
+ wxLogApiError( wxT("pthread_mutex_trylock()"), err );
+ }
+
+ return wxMUTEX_MISC_ERROR;
+}
+
+wxMutexError wxMutexInternal::Unlock()
+{
+ int err = pthread_mutex_unlock( &m_mutex );
+ switch ( err )
+ {
+ case EPERM:
+ // we don't own the mutex
+ return wxMUTEX_UNLOCKED;
+
+ case EINVAL:
+ wxLogDebug( wxT("pthread_mutex_unlock(): mutex not initialized.") );
+ break;
+
+ case 0:
+ return wxMUTEX_NO_ERROR;
+
+ default:
+ wxLogApiError( wxT("pthread_mutex_unlock()"), err );
+ }
+
+ return wxMUTEX_MISC_ERROR;
+}
+
+#endif
+
+#if wxUSE_MAC_SEMAPHORE_MUTEX
+
+class wxMutexInternal
+{