X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..3f4a2351e4c677c88c18ea812b609477adee7380:/src/mac/classic/thread.cpp?ds=sidebyside diff --git a/src/mac/classic/thread.cpp b/src/mac/classic/thread.cpp index 77d12e6e8d..52f7603ee3 100644 --- a/src/mac/classic/thread.cpp +++ b/src/mac/classic/thread.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: thread.cpp +// Name: src/mac/classic/thread.cpp // Purpose: wxThread Implementation // Author: Original from Wolfram Gloger/Guilhem Lavaux/Vadim Zeitlin // Modified by: Stefan Csomor @@ -7,13 +7,9 @@ // RCS-ID: $Id$ // Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998), // Vadim Zeitlin (1999) , Stefan Csomor (2000) -// Licence: wxWidgets licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ - #pragma implementation "thread.h" -#endif - // ---------------------------------------------------------------------------- // headers // ---------------------------------------------------------------------------- @@ -27,11 +23,11 @@ #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__ @@ -64,7 +60,7 @@ enum wxThreadState // ---------------------------------------------------------------------------- static ThreadID gs_idMainThread = kNoThreadID ; -static bool gs_waitingForThread = FALSE ; +static bool gs_waitingForThread = false ; size_t g_numberOfThreads = 0; // ============================================================================ @@ -77,12 +73,18 @@ public : wxMacStCritical() { if ( UMASystemIsInitialized() ) - ThreadBeginCritical() ; + { + OSErr err = ThreadBeginCritical() ; + wxASSERT( err == noErr ) ; + } } ~wxMacStCritical() { if ( UMASystemIsInitialized() ) - ThreadEndCritical() ; + { + OSErr err = ThreadEndCritical() ; + wxASSERT( err == noErr ) ; + } } }; @@ -133,6 +135,7 @@ wxMutexError wxMutexInternal::Lock() m_waiters.Add(current); err = ::SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, m_owner); err = ::ThreadBeginCritical(); + wxASSERT( err == noErr ) ; } m_owner = current; } @@ -165,6 +168,7 @@ wxMutexError wxMutexInternal::Unlock() { OSErr err; err = ::ThreadBeginCritical(); + wxASSERT( err == noErr ) ; if (m_locked > 0) m_locked--; @@ -429,7 +433,7 @@ bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize) if ( err != noErr ) { wxLogSysError(_("Can't create thread")); - return FALSE; + return false; } if ( m_priority != WXTHREAD_DEFAULT_PRIORITY ) @@ -439,27 +443,29 @@ bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize) m_state = STATE_NEW; - return TRUE; + return true; } bool wxThreadInternal::Suspend() { OSErr err ; - ::ThreadBeginCritical(); + err = ::ThreadBeginCritical(); + wxASSERT( err == noErr ) ; if ( m_state != STATE_RUNNING ) { - ::ThreadEndCritical() ; + err = ::ThreadEndCritical() ; + wxASSERT( err == noErr ) ; wxLogSysError(_("Can not suspend thread %x"), m_tid); - return FALSE; + return false; } m_state = STATE_PAUSED; err = ::SetThreadStateEndCritical(m_tid, kStoppedThreadState, kNoThreadID); - return TRUE; + return true; } bool wxThreadInternal::Resume() @@ -471,21 +477,24 @@ bool wxThreadInternal::Resume() wxASSERT( err == noErr ) ; wxASSERT( current != m_tid ) ; - ::ThreadBeginCritical(); + err = ::ThreadBeginCritical(); + wxASSERT( err == noErr ) ; + if ( m_state != STATE_PAUSED && m_state != STATE_NEW ) { - ::ThreadEndCritical() ; + err = ::ThreadEndCritical() ; + wxASSERT( err == noErr ) ; wxLogSysError(_("Can not resume thread %x"), m_tid); - return FALSE; + return false; } err = ::SetThreadStateEndCritical(m_tid, kReadyThreadState, kNoThreadID); - wxASSERT( err == noErr ) ; m_state = STATE_RUNNING; - ::ThreadEndCritical() ; + err = ::ThreadEndCritical() ; + wxASSERT( err == noErr ) ; ::YieldToAnyThread() ; - return TRUE; + return true; } // static functions @@ -536,7 +545,7 @@ void wxThread::Sleep(unsigned long milliseconds) double mssleep = milliseconds * 1000 ; double msstart, msnow ; msstart = (start.hi * 4294967296.0 + start.lo) ; - + do { YieldToAnyThread(); @@ -574,7 +583,7 @@ bool wxThread::SetConcurrency(size_t level) return level == 1; } - return TRUE ; + return true ; } // ctor and dtor @@ -679,7 +688,7 @@ wxThreadError wxThread::Delete(ExitCode *pRc) // Delete() is always safe to call, so consider all possible states // has the thread started to run? - bool shouldResume = FALSE; + bool shouldResume = false; { wxCriticalSectionLocker lock(m_critsect); @@ -689,7 +698,7 @@ wxThreadError wxThread::Delete(ExitCode *pRc) // WinThreadStart() will see it and terminate immediately m_internal->SetState(STATE_EXITED); - shouldResume = TRUE; + shouldResume = true; } } @@ -703,7 +712,7 @@ wxThreadError wxThread::Delete(ExitCode *pRc) if ( IsMain() ) { // set flag for wxIsWaitingForThread() - gs_waitingForThread = TRUE; + gs_waitingForThread = true; #if wxUSE_GUI wxBeginBusyCursor(); @@ -733,7 +742,7 @@ wxThreadError wxThread::Delete(ExitCode *pRc) if ( IsMain() ) { - gs_waitingForThread = FALSE; + gs_waitingForThread = false; #if wxUSE_GUI wxEndBusyCursor(); @@ -870,13 +879,13 @@ bool wxThreadModule::OnInit() if ( !hasThreadManager ) { wxLogSysError( wxT("Thread Support is not available on this System") ); - return FALSE ; + return false ; } // no error return for GetCurrentThreadId() MacGetCurrentThread( &gs_idMainThread ) ; - return TRUE; + return true; } void wxThreadModule::OnExit()