X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/71a660a3128c6c2a9262225136907e57dab33183..7688f0a1f784b6f2f551e63d4eeff7bab3ea46ff:/src/mac/carbon/thread.cpp diff --git a/src/mac/carbon/thread.cpp b/src/mac/carbon/thread.cpp index 8c64c8818a..5e322a719d 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 ; @@ -525,11 +529,20 @@ void wxThread::Yield() void wxThread::Sleep(unsigned long milliseconds) { - clock_t start = clock(); + UnsignedWide start, now; + + Microseconds(&start); + + double mssleep = milliseconds * 1000 ; + double msstart, msnow ; + msstart = (start.hi * 4294967296.0 + start.lo) ; + do { YieldToAnyThread(); - } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ; + Microseconds(&now); + msnow = (now.hi * 4294967296.0 + now.lo) ; + } while( msnow - msstart < mssleep ); } int wxThread::GetCPUCount() @@ -569,6 +582,7 @@ bool wxThread::SetConcurrency(size_t level) wxThread::wxThread(wxThreadKind kind) { + g_numberOfThreads++; m_internal = new wxThreadInternal(); m_isDetached = kind == wxTHREAD_DETACHED; @@ -577,6 +591,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; @@ -844,7 +869,7 @@ bool wxThreadModule::OnInit() #endif if ( !hasThreadManager ) { - wxMessageBox( wxT("Error") , wxT("Thread Support is not available on this System") , wxOK ) ; + wxLogSysError( wxT("Thread Support is not available on this System") ); return FALSE ; }