X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5276b0a53cef4815230e39b54d2ecda14f72cbd1..71a09c3579dd5cb4cd8fa7fdc143561cbff74e12:/src/osx/carbon/thread.cpp?ds=sidebyside diff --git a/src/osx/carbon/thread.cpp b/src/osx/carbon/thread.cpp index e21d6136d7..f4f3d5bd3d 100644 --- a/src/osx/carbon/thread.cpp +++ b/src/osx/carbon/thread.cpp @@ -4,7 +4,6 @@ // Author: Original from Wolfram Gloger/Guilhem Lavaux/Vadim Zeitlin // Modified by: Aj Lavin, Stefan Csomor // Created: 04/22/98 -// RCS-ID: $Id$ // Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998), // Vadim Zeitlin (1999), Stefan Csomor (2000) // Licence: wxWindows licence @@ -121,6 +120,11 @@ void wxCriticalSection::Enter() MPEnterCriticalRegion( (MPCriticalRegionID) m_critRegion, kDurationForever ); } +bool wxCriticalSection::TryEnter() +{ + return MPEnterCriticalRegion( (MPCriticalRegionID) m_critRegion, kDurationImmediate ) == noErr; +} + void wxCriticalSection::Leave() { MPExitCriticalRegion( (MPCriticalRegionID) m_critRegion ); @@ -470,7 +474,7 @@ public: { m_tid = kInvalidID; m_state = STATE_NEW; - m_prio = WXTHREAD_DEFAULT_PRIORITY; + m_prio = wxPRIORITY_DEFAULT; m_notifyQueueId = kInvalidID; m_exitcode = 0; m_cancelled = false ; @@ -651,6 +655,9 @@ bool wxThreadInternal::Create( wxThread *thread, unsigned int stackSize ) wxASSERT_MSG( m_state == STATE_NEW && !m_tid, wxT("Create()ing thread twice?") ); + if ( thread->IsDetached() ) + Detach(); + OSStatus err = noErr; m_thread = thread; @@ -659,7 +666,7 @@ bool wxThreadInternal::Create( wxThread *thread, unsigned int stackSize ) OSStatus err = MPCreateQueue( &m_notifyQueueId ); if (err != noErr) { - wxLogSysError( wxT("Cant create the thread event queue") ); + wxLogSysError( wxT("Can't create the thread event queue") ); return false; } @@ -678,7 +685,7 @@ bool wxThreadInternal::Create( wxThread *thread, unsigned int stackSize ) return false; } - if ( m_prio != WXTHREAD_DEFAULT_PRIORITY ) + if ( m_prio != wxPRIORITY_DEFAULT ) SetPriority( m_prio ); return true; @@ -863,13 +870,9 @@ wxThreadError wxThread::Create( unsigned int stackSize ) { wxCriticalSectionLocker lock(m_critsect); - if ( m_isDetached ) - m_internal->Detach() ; - if ( !m_internal->Create(this, stackSize) ) { m_internal->SetState( STATE_EXITED ); - return wxTHREAD_NO_RESOURCE; } @@ -880,6 +883,17 @@ wxThreadError wxThread::Run() { wxCriticalSectionLocker lock(m_critsect); + // Create the thread if it wasn't created yet with an explicit + // Create() call: + if ( m_internal->GetId() == kInvalidID ) + { + if ( !m_internal->Create(this, stackSize) ) + { + m_internal->SetState( STATE_EXITED ); + return wxTHREAD_NO_RESOURCE; + } + } + wxCHECK_MSG( m_internal->GetId(), wxTHREAD_MISC_ERROR, wxT("must call wxThread::Create() first") ); @@ -940,7 +954,7 @@ wxThreadError wxThread::Resume() // exiting thread // ----------------------------------------------------------------------------- -wxThread::ExitCode wxThread::Wait() +wxThread::ExitCode wxThread::Wait(wxThreadWait WXUNUSED(waitMode)) { wxCHECK_MSG( This() != this, (ExitCode)-1, wxT("a thread can't wait for itself") ); @@ -953,7 +967,7 @@ wxThread::ExitCode wxThread::Wait() return m_internal->GetExitCode(); } -wxThreadError wxThread::Delete(ExitCode *rc) +wxThreadError wxThread::Delete(ExitCode *rc, wxThreadWait WXUNUSED(waitMode)) { wxCHECK_MSG( This() != this, wxTHREAD_MISC_ERROR, wxT("a thread can't delete itself") ); @@ -1105,8 +1119,7 @@ bool wxThread::TestDestroy() void wxThread::SetPriority(unsigned int prio) { - wxCHECK_RET( ((int)WXTHREAD_MIN_PRIORITY <= (int)prio) && - ((int)prio <= (int)WXTHREAD_MAX_PRIORITY), + wxCHECK_RET( wxPRIORITY_MIN <= prio && prio <= wxPRIORITY_MAX, wxT("invalid thread priority") ); wxCriticalSectionLocker lock(m_critsect); @@ -1128,14 +1141,14 @@ void wxThread::SetPriority(unsigned int prio) unsigned int wxThread::GetPriority() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return m_internal->GetPriority(); } unsigned long wxThread::GetId() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return (unsigned long)m_internal->GetId(); }