X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/420b39aa4b6117a0cf192266ea6f3ed61cbcc1e0..47e175a24f862aa8b7ca7dd4a2bb5957991e7f2d:/src/osx/carbon/thread.cpp diff --git a/src/osx/carbon/thread.cpp b/src/osx/carbon/thread.cpp index ded1084d36..e8ab4cd0fe 100644 --- a/src/osx/carbon/thread.cpp +++ b/src/osx/carbon/thread.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/thread.cpp +// Name: src/osx/carbon/thread.cpp // Purpose: wxThread Implementation // Author: Original from Wolfram Gloger/Guilhem Lavaux/Vadim Zeitlin // Modified by: Aj Lavin, Stefan Csomor @@ -49,7 +49,7 @@ enum wxThreadState // ---------------------------------------------------------------------------- // the task ID of the main thread -static wxThreadIdType gs_idMainThread = kInvalidID; +wxThreadIdType wxThread::ms_idMainThread = kInvalidID; // this is the Per-Task Storage for the pointer to the appropriate wxThread TaskStorageIndex gs_tlsForWXThread = 0; @@ -106,7 +106,7 @@ MPCriticalRegionID gs_guiCritical = kInvalidID; // wxCriticalSection // ---------------------------------------------------------------------------- -wxCriticalSection::wxCriticalSection() +wxCriticalSection::wxCriticalSection( wxCriticalSectionType WXUNUSED(critSecType) ) { MPCreateCriticalRegion( (MPCriticalRegionID*) &m_critRegion ); } @@ -121,6 +121,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 ); @@ -343,7 +348,7 @@ private: wxMutex& m_mutex; wxSemaphore m_semaphore; - DECLARE_NO_COPY_CLASS(wxConditionInternal) + wxDECLARE_NO_COPY_CLASS(wxConditionInternal); }; wxConditionInternal::wxConditionInternal( wxMutex& mutex ) @@ -470,7 +475,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 ; @@ -659,7 +664,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 +683,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; @@ -796,11 +801,6 @@ wxThread *wxThread::This() return thr; } -bool wxThread::IsMain() -{ - return GetCurrentId() == gs_idMainThread || gs_idMainThread == kInvalidID ; -} - #ifdef Yield #undef Yield #endif @@ -848,7 +848,6 @@ wxThread::~wxThread() g_numberOfThreads--; -#ifdef __WXDEBUG__ m_critsect.Enter(); // check that the thread either exited or couldn't be created @@ -861,7 +860,6 @@ wxThread::~wxThread() } m_critsect.Leave(); -#endif wxDELETE( m_internal ) ; } @@ -900,7 +898,7 @@ wxThreadError wxThread::Run() wxThreadError wxThread::Pause() { wxCHECK_MSG( This() != this, wxTHREAD_MISC_ERROR, - _T("a thread can't pause itself") ); + wxT("a thread can't pause itself") ); wxCriticalSectionLocker lock(m_critsect); @@ -947,7 +945,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") ); @@ -960,7 +958,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") ); @@ -1112,8 +1110,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); @@ -1135,14 +1132,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(); } @@ -1198,8 +1195,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) bool wxThreadModule::OnInit() { - bool hasThreadManager = -#ifdef __LP64__ + bool hasThreadManager = +#ifdef __LP64__ true ; // TODO VERIFY IN NEXT BUILD #else MPLibraryIsLoaded(); @@ -1216,7 +1213,7 @@ bool wxThreadModule::OnInit() verify_noerr( MPAllocateTaskStorageIndex( &gs_tlsForWXThread ) ) ; verify_noerr( MPSetTaskStorageValue( gs_tlsForWXThread, 0 ) ) ; - gs_idMainThread = wxThread::GetCurrentId(); + wxThread::ms_idMainThread = wxThread::GetCurrentId(); gs_critsectWaitingForGui = new wxCriticalSection(); gs_critsectGui = new wxCriticalSection(); @@ -1236,12 +1233,10 @@ void wxThreadModule::OnExit() } gs_critsectGui->Leave(); - delete gs_critsectGui; - gs_critsectGui = NULL; + wxDELETE(gs_critsectGui); } - delete gs_critsectWaitingForGui; - gs_critsectWaitingForGui = NULL; + wxDELETE(gs_critsectWaitingForGui); } // ----------------------------------------------------------------------------