From e64313babfa84d2806313c611503e517390b3731 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Mon, 24 Nov 2003 20:53:35 +0000 Subject: [PATCH] Applied patch #809919 (Allows wxMac threads to run at fullspeed). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24660 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/app.cpp | 23 +++++++++++++++++++++-- src/mac/carbon/app.cpp | 23 +++++++++++++++++++++-- src/mac/carbon/thread.cpp | 15 ++++++++++++++- src/mac/thread.cpp | 15 ++++++++++++++- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 2ff6ed261d..788986f20e 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -69,6 +69,7 @@ extern wxList wxPendingDelete; extern wxList *wxWinMacWindowList; extern wxList *wxWinMacControlList; +extern size_t g_numberOfThreads; // statics for implementation @@ -1250,7 +1251,16 @@ void wxApp::MacDoOneEvent() if ( wxTheApp->ProcessIdle() ) sleepTime = kEventDurationNoWait ; else - sleepTime = kEventDurationForever ; + { + if (g_numberOfThreads) + { + sleepTime = kEventDurationNoWait; + } + else + { + sleepTime = kEventDurationSecond; + } + } } else if ( status == eventLoopQuitErr ) { @@ -1284,7 +1294,16 @@ void wxApp::MacDoOneEvent() if ( wxTheApp->ProcessIdle() ) sleepTime = kEventDurationNoWait; else - sleepTime = GetCaretTime() / 2 ; + { + if (g_numberOfThreads) + { + sleepTime = kEventDurationNoWait; + } + else + { + sleepTime = kEventDurationSecond; + } + } } if ( event.what != kHighLevelEvent ) SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 2ff6ed261d..788986f20e 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -69,6 +69,7 @@ extern wxList wxPendingDelete; extern wxList *wxWinMacWindowList; extern wxList *wxWinMacControlList; +extern size_t g_numberOfThreads; // statics for implementation @@ -1250,7 +1251,16 @@ void wxApp::MacDoOneEvent() if ( wxTheApp->ProcessIdle() ) sleepTime = kEventDurationNoWait ; else - sleepTime = kEventDurationForever ; + { + if (g_numberOfThreads) + { + sleepTime = kEventDurationNoWait; + } + else + { + sleepTime = kEventDurationSecond; + } + } } else if ( status == eventLoopQuitErr ) { @@ -1284,7 +1294,16 @@ void wxApp::MacDoOneEvent() if ( wxTheApp->ProcessIdle() ) sleepTime = kEventDurationNoWait; else - sleepTime = GetCaretTime() / 2 ; + { + if (g_numberOfThreads) + { + sleepTime = kEventDurationNoWait; + } + else + { + sleepTime = kEventDurationSecond; + } + } } if ( event.what != kHighLevelEvent ) SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; diff --git a/src/mac/carbon/thread.cpp b/src/mac/carbon/thread.cpp index 8c6e856cc6..3634a69dde 100644 --- a/src/mac/carbon/thread.cpp +++ b/src/mac/carbon/thread.cpp @@ -64,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 @@ -531,7 +532,7 @@ void wxThread::Sleep(unsigned long milliseconds) do { YieldToAnyThread(); - } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ; + } while( clock() - start < milliseconds * CLOCKS_PER_SEC / 1000.0 ) ; } int wxThread::GetCPUCount() @@ -571,6 +572,7 @@ bool wxThread::SetConcurrency(size_t level) wxThread::wxThread(wxThreadKind kind) { + g_numberOfThreads++; m_internal = new wxThreadInternal(); m_isDetached = kind == wxTHREAD_DETACHED; @@ -579,6 +581,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; diff --git a/src/mac/thread.cpp b/src/mac/thread.cpp index 8c6e856cc6..3634a69dde 100644 --- a/src/mac/thread.cpp +++ b/src/mac/thread.cpp @@ -64,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 @@ -531,7 +532,7 @@ void wxThread::Sleep(unsigned long milliseconds) do { YieldToAnyThread(); - } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ; + } while( clock() - start < milliseconds * CLOCKS_PER_SEC / 1000.0 ) ; } int wxThread::GetCPUCount() @@ -571,6 +572,7 @@ bool wxThread::SetConcurrency(size_t level) wxThread::wxThread(wxThreadKind kind) { + g_numberOfThreads++; m_internal = new wxThreadInternal(); m_isDetached = kind == wxTHREAD_DETACHED; @@ -579,6 +581,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; -- 2.45.2