+
+ 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
+{
+public:
+ wxMutexInternal( wxMutexType mutexType );
+ virtual ~wxMutexInternal();
+
+ bool IsOk() const
+ { return m_isOk; }
+
+ wxMutexError Lock();
+ wxMutexError TryLock();
+ wxMutexError Unlock();
+
+private:
+ MPSemaphoreID m_semaphore;
+ bool m_isOk;
+};
+
+wxMutexInternal::wxMutexInternal(wxMutexType mutexType )
+{
+ m_isOk = false;
+ m_semaphore = kInvalidID;
+ OSStatus err = noErr;
+
+ switch ( mutexType )
+ {
+ case wxMUTEX_DEFAULT :
+ verify_noerr( MPCreateBinarySemaphore( &m_semaphore ) );
+ m_isOk = ( m_semaphore != kInvalidID );
+ break;
+
+ case wxMUTEX_RECURSIVE :
+ wxFAIL_MSG( wxT("Recursive Mutex not supported yet") );
+ break;
+
+ default :
+ wxFAIL_MSG( wxT("Unknown mutex type") );
+ break;
+ }
+}
+
+wxMutexInternal::~wxMutexInternal()
+{
+ if ( m_semaphore != kInvalidID )
+ MPDeleteSemaphore( m_semaphore );
+
+ MPYield();
+}
+
+wxMutexError wxMutexInternal::Lock()
+{
+ wxCHECK_MSG( m_isOk, wxMUTEX_MISC_ERROR, wxT("Invalid Mutex") );
+ OSStatus err = MPWaitOnSemaphore( m_semaphore, kDurationForever );
+ if (err != noErr)
+ {
+ wxLogSysError( wxT("Could not lock mutex") );
+
+ return wxMUTEX_MISC_ERROR;
+ }
+