X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/66a09d4776b8ae390d5aa51dbd678b694f2c81d6..0fe5e8fea017ecb73f8aaa8ceb745feb269b3f79:/src/mac/thread.cpp diff --git a/src/mac/thread.cpp b/src/mac/thread.cpp index dce44db526..e59ca72ebe 100644 --- a/src/mac/thread.cpp +++ b/src/mac/thread.cpp @@ -35,9 +35,7 @@ #include "wx/thread.h" #ifdef __WXMAC__ -#ifndef __DARWIN__ #include -#endif #include "wx/mac/uma.h" #endif @@ -70,7 +68,7 @@ static bool gs_waitingForThread = FALSE ; class wxMacStCritical { public : - wxMacStCritical() + wxMacStCritical() { if ( UMASystemIsInitialized() ) ThreadBeginCritical() ; @@ -94,7 +92,7 @@ public: m_owner = kNoThreadID ; } - ~wxMutexInternal() + ~wxMutexInternal() { } @@ -130,7 +128,7 @@ wxMutexError wxMutex::Lock() err = ::MacGetCurrentThread(¤t); // if we are not the owner, add this thread to the list of waiting threads, stop this thread // and invoke the scheduler to continue executing the owner's thread - while ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current) + while ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current) { m_internal->m_waiters.Add(current); err = ::SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, m_internal->m_owner); @@ -147,14 +145,14 @@ wxMutexError wxMutex::TryLock() { wxMacStCritical critical ; if ( UMASystemIsInitialized() ) - { + { OSErr err ; ThreadID current = kNoThreadID; ::MacGetCurrentThread(¤t); // if we are not the owner, give an error back - if ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current ) + if ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current ) return wxMUTEX_BUSY; - + m_internal->m_owner = current; } m_locked++; @@ -165,10 +163,10 @@ wxMutexError wxMutex::TryLock() wxMutexError wxMutex::Unlock() { if ( UMASystemIsInitialized() ) - { + { OSErr err; err = ::ThreadBeginCritical(); - + if (m_locked > 0) m_locked--; @@ -178,12 +176,12 @@ wxMutexError wxMutex::Unlock() // now pass on to the first waiting thread ThreadID firstWaiting = kNoThreadID; bool found = false; - while (!m_internal->m_waiters.IsEmpty() && !found) + while (!m_internal->m_waiters.IsEmpty() && !found) { firstWaiting = m_internal->m_waiters[0]; err = ::SetThreadState(firstWaiting, kReadyThreadState, kNoThreadID); // in case this was not successful (dead thread), we just loop on and reset the id - found = (err != threadNotFoundErr); + found = (err != threadNotFoundErr); if ( !found ) firstWaiting = kNoThreadID ; m_internal->m_waiters.RemoveAt(0) ; @@ -339,7 +337,7 @@ public: // thread priority void SetPriority(unsigned int priority); unsigned int GetPriority() const { return m_priority; } - + void SetResult( void *res ) { m_result = res ; } void *GetResult() { return m_result ; } @@ -425,7 +423,7 @@ bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize) bool wxThreadInternal::Suspend() { OSErr err ; - + ::ThreadBeginCritical(); if ( m_state != STATE_RUNNING ) @@ -450,18 +448,18 @@ bool wxThreadInternal::Resume() wxASSERT( err == noErr ) ; wxASSERT( current != m_tid ) ; - + ::ThreadBeginCritical(); if ( m_state != STATE_PAUSED && m_state != STATE_NEW ) { ::ThreadEndCritical() ; wxLogSysError(_("Can not resume thread %x"), m_tid); return FALSE; - + } err = ::SetThreadStateEndCritical(m_tid, kReadyThreadState, kNoThreadID); wxASSERT( err == noErr ) ; - + m_state = STATE_RUNNING; ::ThreadEndCritical() ; ::YieldToAnyThread() ; @@ -473,12 +471,12 @@ bool wxThreadInternal::Resume() wxThread *wxThread::This() { wxMacStCritical critical ; - + ThreadID current ; OSErr err ; - + err = MacGetCurrentThread( ¤t ) ; - + for ( int i = 0 ; i < s_threads.Count() ; ++i ) { if ( ( (wxThread*) s_threads[i] )->GetId() == current ) @@ -493,7 +491,7 @@ bool wxThread::IsMain() { ThreadID current ; OSErr err ; - + err = MacGetCurrentThread( ¤t ) ; return current == gs_idMainThread; } @@ -510,7 +508,7 @@ void wxThread::Yield() void wxThread::Sleep(unsigned long milliseconds) { clock_t start = clock() ; - do + do { YieldToAnyThread() ; } while( clock() - start < milliseconds / CLOCKS_PER_SEC ) ; @@ -522,6 +520,13 @@ int wxThread::GetCPUCount() return 1; } +unsigned long wxThread::GetCurrentId() +{ + ThreadID current ; + MacGetCurrentThread( ¤t ) ; + return (unsigned long)current; +} + bool wxThread::SetConcurrency(size_t level) { wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") ); @@ -537,7 +542,7 @@ bool wxThread::SetConcurrency(size_t level) // processor system it doesn't make much sense anyhow return level == 1; } - + return TRUE ; } @@ -748,7 +753,7 @@ void wxThread::Exit(ExitCode status) m_internal->SetResult( status ) ; -/* +/* #if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500)) _endthreadex((unsigned)status); #else // !VC++ @@ -864,7 +869,7 @@ bool WXDLLEXPORT wxGuiOwnedByMainThread() return false ; } -// wake up the main thread +// wake up the main thread void WXDLLEXPORT wxWakeUpMainThread() { wxMacWakeUp() ;