X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/18680f86512504f043ad5d0b222afc7be87aa3e9..8064223b7b1b3657363b7a635c381b9269d95e55:/src/mac/carbon/thread.cpp diff --git a/src/mac/carbon/thread.cpp b/src/mac/carbon/thread.cpp index 2a2f9a7440..04383b0f94 100644 --- a/src/mac/carbon/thread.cpp +++ b/src/mac/carbon/thread.cpp @@ -18,26 +18,15 @@ #ifndef WX_PRECOMP #include "wx/wx.h" + #include "wx/module.h" #endif #if wxUSE_THREADS -#include "wx/module.h" #include "wx/thread.h" -#ifdef __WXMAC__ -#ifdef __DARWIN__ - #include -#else - #include - #include -#endif - +#include #include "wx/mac/uma.h" -#endif - -#include "wx/mac/macnotfy.h" - // the possible states of the thread: // ("=>" shows all possible transitions from this state) @@ -136,15 +125,9 @@ void wxCriticalSection::Leave() // wxMutex implementation // ---------------------------------------------------------------------------- -#if TARGET_API_MAC_OSX #define wxUSE_MAC_SEMAPHORE_MUTEX 0 #define wxUSE_MAC_CRITICAL_REGION_MUTEX 1 #define wxUSE_MAC_PTHREADS_MUTEX 0 -#else -#define wxUSE_MAC_SEMAPHORE_MUTEX 0 -#define wxUSE_MAC_CRITICAL_REGION_MUTEX 1 -#define wxUSE_MAC_PTHREADS_MUTEX 0 -#endif #if wxUSE_MAC_PTHREADS_MUTEX @@ -418,10 +401,10 @@ public: wxMutexInternal( wxMutexType mutexType ); virtual ~wxMutexInternal(); - bool IsOk() const - { return m_isOk; } + bool IsOk() const { return m_isOk; } - wxMutexError Lock() ; + wxMutexError Lock() { return Lock(kDurationForever); } + wxMutexError Lock(unsigned long ms); wxMutexError TryLock(); wxMutexError Unlock(); @@ -430,7 +413,7 @@ private: bool m_isOk ; }; -wxMutexInternal::wxMutexInternal( wxMutexType mutexType ) +wxMutexInternal::wxMutexInternal( wxMutexType WXUNUSED(mutexType) ) { m_isOk = false; m_critRegion = kInvalidID; @@ -451,15 +434,23 @@ wxMutexInternal::~wxMutexInternal() MPYield(); } -wxMutexError wxMutexInternal::Lock() +wxMutexError wxMutexInternal::Lock(unsigned long ms) { wxCHECK_MSG( m_isOk , wxMUTEX_MISC_ERROR , wxT("Invalid Mutex") ); - OSStatus err = MPEnterCriticalRegion( m_critRegion, kDurationForever); - if (err != noErr) + OSStatus err = MPEnterCriticalRegion( m_critRegion, ms ); + switch ( err ) { - wxLogSysError(wxT("Could not lock mutex")); - return wxMUTEX_MISC_ERROR; + case noErr: + break; + + case kMPTimeoutErr: + wxASSERT_MSG( ms != kDurationForever, wxT("unexpected timeout") ); + return wxMUTEX_TIMEOUT; + + default: + wxLogSysError(wxT("Could not lock mutex")); + return wxMUTEX_MISC_ERROR; } return wxMUTEX_NO_ERROR; @@ -829,7 +820,7 @@ wxCondError wxConditionInternal::WaitTimeout( unsigned long milliseconds ) wxSemaError err = m_semaphore.WaitTimeout(milliseconds); - if ( err == wxSEMA_BUSY ) + if ( err == wxSEMA_TIMEOUT ) { // another potential race condition exists here it is caused when a // 'waiting' thread timesout, and returns from WaitForSingleObject, but @@ -1039,7 +1030,7 @@ OSStatus wxThreadInternal::MacThreadStart(void *parameter) wxThreadInternal *pthread = thread->m_internal; // add to TLS so that This() will work - verify_noerr( MPSetTaskStorageValue( gs_tlsForWXThread , (long) thread ) ) ; + verify_noerr( MPSetTaskStorageValue( gs_tlsForWXThread , (TaskStorageValue) thread ) ) ; // have to declare this before pthread_cleanup_push() which defines a // block! @@ -1247,9 +1238,7 @@ bool wxThread::IsMain() void wxThread::Yield() { -#if TARGET_API_MAC_OSX CFRunLoopRunInMode( kCFRunLoopDefaultMode , 0 , true ) ; -#endif MPYield(); } @@ -1270,7 +1259,7 @@ unsigned long wxThread::GetCurrentId() return (unsigned long)MPCurrentTaskID(); } -bool wxThread::SetConcurrency( size_t level ) +bool wxThread::SetConcurrency( size_t WXUNUSED(level) ) { // Cannot be set in MacOS. return false; @@ -1640,7 +1629,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) bool wxThreadModule::OnInit() { - bool hasThreadManager = MPLibraryIsLoaded(); + bool hasThreadManager = +#ifdef __LP64__ + true ; // TODO VERIFY IN NEXT BUILD +#else + MPLibraryIsLoaded(); +#endif if ( !hasThreadManager ) { @@ -1685,7 +1679,7 @@ void wxThreadModule::OnExit() // GUI Serialization copied from MSW implementation // ---------------------------------------------------------------------------- -void WXDLLIMPEXP_BASE wxMutexGuiEnter() +void wxMutexGuiEnterImpl() { // this would dead lock everything... wxASSERT_MSG( !wxThread::IsMain(), @@ -1707,7 +1701,7 @@ void WXDLLIMPEXP_BASE wxMutexGuiEnter() gs_critsectGui->Enter(); } -void WXDLLIMPEXP_BASE wxMutexGuiLeave() +void wxMutexGuiLeaveImpl() { wxCriticalSectionLocker enter(*gs_critsectWaitingForGui);