X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad816ba53975de78ea29acdc40f05217137c8ad3..b77b87881bae2e6306366d79e7fe160334b3d4a2:/src/mac/thread.cpp?ds=inline diff --git a/src/mac/thread.cpp b/src/mac/thread.cpp index 5ce510da31..3634a69dde 100644 --- a/src/mac/thread.cpp +++ b/src/mac/thread.cpp @@ -37,10 +37,12 @@ #ifdef __WXMAC__ #include #include "wx/mac/uma.h" +#include "wx/mac/macnotfy.h" #endif #define INFINITE 0xFFFFFFFF + // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -62,6 +64,7 @@ enum wxThreadState static ThreadID gs_idMainThread = kNoThreadID ; static bool gs_waitingForThread = FALSE ; +size_t g_numberOfThreads = 0; // ============================================================================ // MacOS implementation of thread classes @@ -99,7 +102,7 @@ public: { if ( m_locked > 0 ) { - wxLogDebug(_T("Warning: freeing a locked mutex (%d locks)."), m_locked); + wxLogDebug(_T("Warning: freeing a locked mutex (%ld locks)."), m_locked); } } @@ -257,12 +260,12 @@ public: } bool IsOk() const { return m_mutex.IsOk() ; } - + wxCondError Wait() { return WaitTimeout(0xFFFFFFFF ); } - + wxCondError WaitTimeout(unsigned long msectimeout) { wxMacStCritical critical ; @@ -300,7 +303,7 @@ public: { wxMacStCritical critical ; return wxCOND_NO_ERROR; - } + } wxArrayLong m_waiters ; wxInt32 m_excessSignals ; @@ -433,6 +436,8 @@ bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize) SetPriority(m_priority); } + m_state = STATE_NEW; + return TRUE; } @@ -523,11 +528,11 @@ void wxThread::Yield() void wxThread::Sleep(unsigned long milliseconds) { - clock_t start = clock() ; - do - { - YieldToAnyThread() ; - } while( clock() - start < milliseconds / CLOCKS_PER_SEC ) ; + clock_t start = clock(); + do + { + YieldToAnyThread(); + } while( clock() - start < milliseconds * CLOCKS_PER_SEC / 1000.0 ) ; } int wxThread::GetCPUCount() @@ -567,6 +572,7 @@ bool wxThread::SetConcurrency(size_t level) wxThread::wxThread(wxThreadKind kind) { + g_numberOfThreads++; m_internal = new wxThreadInternal(); m_isDetached = kind == wxTHREAD_DETACHED; @@ -575,8 +581,22 @@ 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 ) ; - delete m_internal; + if (m_internal != NULL) { + delete m_internal; + m_internal = NULL; + } } // create/start thread @@ -711,13 +731,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 @@ -727,9 +740,6 @@ wxThreadError wxThread::Delete(ExitCode *pRc) delete this; } - // wxASSERT_MSG( (DWORD)rc != STILL_ACTIVE, - // wxT("thread must be already terminated.") ); - if ( pRc ) *pRc = rc; @@ -849,7 +859,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 ; } @@ -899,5 +909,3 @@ bool WXDLLEXPORT wxIsWaitingForThread() #include "wx/thrimpl.cpp" #endif // wxUSE_THREADS - -// vi:sts=4:sw=4:et