From 26dd1a009516062a99e06d5e1b0c75c7b01ec294 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 2 Feb 2003 15:28:29 +0000 Subject: [PATCH] optimizing sleep values git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@19077 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/app.cpp | 23 +++++++++++++++-------- src/mac/carbon/app.cpp | 23 +++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/mac/app.cpp b/src/mac/app.cpp index eb0e9ede10..9587df5d9e 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -73,6 +73,8 @@ extern wxList wxPendingDelete; extern wxList *wxWinMacWindowList; extern wxList *wxWinMacControlList; +static long sleepTime = 0 ; + wxApp *wxTheApp = NULL; #if !USE_SHARED_LIBRARY @@ -1370,16 +1372,19 @@ bool wxApp::Yield(bool onlyIfNeeded) #endif EventRecord event ; - long sleepTime = 1 ; //::GetCaretTime(); + // having a larger value here leads to large performance slowdowns + // so we cannot give background apps more processor time here + // we do so however having a large sleep value in the main event loop + sleepTime = 0 ; - while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) + while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) { - wxTheApp->MacHandleModifierEvents( &event ) ; - wxTheApp->MacHandleOneEvent( &event ); + MacHandleModifierEvents( &event ) ; + MacHandleOneEvent( &event ); if ( event.what != kHighLevelEvent ) SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; } - wxTheApp->MacHandleModifierEvents( &event ) ; + MacHandleModifierEvents( &event ) ; wxMacProcessNotifierAndPendingEvents() ; @@ -1448,12 +1453,11 @@ void wxApp::MacDoOneEvent() { EventRecord event ; - long sleepTime = 1; // GetCaretTime() / 4 ; - if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn)) { MacHandleModifierEvents( &event ) ; MacHandleOneEvent( &event ); + sleepTime = 0 ; } else { @@ -1463,7 +1467,10 @@ void wxApp::MacDoOneEvent() if ( window ) ::IdleControls( window ) ; - wxTheApp->ProcessIdle() ; + if ( wxTheApp->ProcessIdle() ) + sleepTime = 0 ; + else + sleepTime = GetCaretTime() / 2 ; } 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 eb0e9ede10..9587df5d9e 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -73,6 +73,8 @@ extern wxList wxPendingDelete; extern wxList *wxWinMacWindowList; extern wxList *wxWinMacControlList; +static long sleepTime = 0 ; + wxApp *wxTheApp = NULL; #if !USE_SHARED_LIBRARY @@ -1370,16 +1372,19 @@ bool wxApp::Yield(bool onlyIfNeeded) #endif EventRecord event ; - long sleepTime = 1 ; //::GetCaretTime(); + // having a larger value here leads to large performance slowdowns + // so we cannot give background apps more processor time here + // we do so however having a large sleep value in the main event loop + sleepTime = 0 ; - while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) + while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) { - wxTheApp->MacHandleModifierEvents( &event ) ; - wxTheApp->MacHandleOneEvent( &event ); + MacHandleModifierEvents( &event ) ; + MacHandleOneEvent( &event ); if ( event.what != kHighLevelEvent ) SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; } - wxTheApp->MacHandleModifierEvents( &event ) ; + MacHandleModifierEvents( &event ) ; wxMacProcessNotifierAndPendingEvents() ; @@ -1448,12 +1453,11 @@ void wxApp::MacDoOneEvent() { EventRecord event ; - long sleepTime = 1; // GetCaretTime() / 4 ; - if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn)) { MacHandleModifierEvents( &event ) ; MacHandleOneEvent( &event ); + sleepTime = 0 ; } else { @@ -1463,7 +1467,10 @@ void wxApp::MacDoOneEvent() if ( window ) ::IdleControls( window ) ; - wxTheApp->ProcessIdle() ; + if ( wxTheApp->ProcessIdle() ) + sleepTime = 0 ; + else + sleepTime = GetCaretTime() / 2 ; } if ( event.what != kHighLevelEvent ) SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;