X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f5bb2251332040fd8ac7adb9406ea2516a077ed6..30e0b1c9720fcef5fb2fa0969ef4cc12a168cf97:/src/mac/carbon/thread.cpp?ds=sidebyside diff --git a/src/mac/carbon/thread.cpp b/src/mac/carbon/thread.cpp index 5ea6f21f32..db758b346f 100644 --- a/src/mac/carbon/thread.cpp +++ b/src/mac/carbon/thread.cpp @@ -37,10 +37,13 @@ #ifdef __WXMAC__ #include #include "wx/mac/uma.h" +#include "wx/mac/macnotfy.h" +#include #endif #define INFINITE 0xFFFFFFFF + // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -62,6 +65,7 @@ enum wxThreadState static ThreadID gs_idMainThread = kNoThreadID ; static bool gs_waitingForThread = FALSE ; +size_t g_numberOfThreads = 0; // ============================================================================ // MacOS implementation of thread classes @@ -257,12 +261,12 @@ public: } bool IsOk() const { return m_mutex.IsOk() ; } - + wxCondError Wait() { return WaitTimeout(0xFFFFFFFF ); } - + wxCondError WaitTimeout(unsigned long msectimeout) { wxMacStCritical critical ; @@ -300,7 +304,7 @@ public: { wxMacStCritical critical ; return wxCOND_NO_ERROR; - } + } wxArrayLong m_waiters ; wxInt32 m_excessSignals ; @@ -433,6 +437,8 @@ bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize) SetPriority(m_priority); } + m_state = STATE_NEW; + return TRUE; } @@ -518,16 +524,29 @@ bool wxThread::IsMain() void wxThread::Yield() { +#if TARGET_API_MAC_OSX + CFRunLoopRunInMode( kCFRunLoopDefaultMode , 0 , true ) ; +#endif ::YieldToAnyThread() ; + } void wxThread::Sleep(unsigned long milliseconds) { - clock_t start = clock() ; - do - { - YieldToAnyThread() ; - } while( clock() - start < milliseconds / CLOCKS_PER_SEC ) ; + UnsignedWide start, now; + + Microseconds(&start); + + double mssleep = milliseconds * 1000 ; + double msstart, msnow ; + msstart = (start.hi * 4294967296.0 + start.lo) ; + + do + { + YieldToAnyThread(); + Microseconds(&now); + msnow = (now.hi * 4294967296.0 + now.lo) ; + } while( msnow - msstart < mssleep ); } int wxThread::GetCPUCount() @@ -567,6 +586,7 @@ bool wxThread::SetConcurrency(size_t level) wxThread::wxThread(wxThreadKind kind) { + g_numberOfThreads++; m_internal = new wxThreadInternal(); m_isDetached = kind == wxTHREAD_DETACHED; @@ -575,6 +595,17 @@ wxThread::wxThread(wxThreadKind kind) wxThread::~wxThread() { + if (g_numberOfThreads>0) + { + g_numberOfThreads--; + } +#ifdef __WXDEBUG__ + else + { + wxFAIL_MSG(wxT("More threads deleted than created.")); + } +#endif + s_threads.Remove( (void*) this ) ; if (m_internal != NULL) { delete m_internal; @@ -714,13 +745,6 @@ wxThreadError wxThread::Delete(ExitCode *pRc) } } - // if ( !::GetExitCodeThread(hThread, (LPDWORD)&rc) ) - { - wxLogLastError("GetExitCodeThread"); - - rc = (ExitCode)-1; - } - if ( IsDetached() ) { // if the thread exits normally, this is done in WinThreadStart, but in @@ -730,9 +754,6 @@ wxThreadError wxThread::Delete(ExitCode *pRc) delete this; } - // wxASSERT_MSG( (DWORD)rc != STILL_ACTIVE, - // wxT("thread must be already terminated.") ); - if ( pRc ) *pRc = rc; @@ -852,7 +873,7 @@ bool wxThreadModule::OnInit() #endif if ( !hasThreadManager ) { - wxMessageBox( "Error" , "Thread Support is not available on this System" , wxOK ) ; + wxLogSysError( wxT("Thread Support is not available on this System") ); return FALSE ; } @@ -902,5 +923,3 @@ bool WXDLLEXPORT wxIsWaitingForThread() #include "wx/thrimpl.cpp" #endif // wxUSE_THREADS - -// vi:sts=4:sw=4:et