Kaydet (Commit) 3f64e7c1 authored tarafından Tobias Madl's avatar Tobias Madl

Optimized Timer/Idle code

Change-Id: I285bd632faba5a29a770404d6967f4faf7667b16
üst 4c3cea26
...@@ -64,6 +64,7 @@ public: ...@@ -64,6 +64,7 @@ public:
static void ImplDeInitTimer(); static void ImplDeInitTimer();
static void ImplTimerCallbackProc(); static void ImplTimerCallbackProc();
static bool TimerReady(); static bool TimerReady();
static bool CheckExpiredTimer(const bool bDoInvoke);
}; };
/// An auto-timer is a multi-shot timer re-emitting itself at /// An auto-timer is a multi-shot timer re-emitting itself at
......
...@@ -320,7 +320,6 @@ struct ImplSVData ...@@ -320,7 +320,6 @@ struct ImplSVData
sal_uLong mnTimerPeriod; // current timer period sal_uLong mnTimerPeriod; // current timer period
sal_uLong mnTimerUpdate; // TimerCallbackProcs on stack sal_uLong mnTimerUpdate; // TimerCallbackProcs on stack
bool mbNotAllTimerCalled; // true: Timer must still be processed bool mbNotAllTimerCalled; // true: Timer must still be processed
bool mbNoCallTimer; // true: No Timeout calls
ImplSVAppData maAppData; // indepen data for class Application ImplSVAppData maAppData; // indepen data for class Application
ImplSVGDIData maGDIData; // indepen data for Output classes ImplSVGDIData maGDIData; // indepen data for Output classes
ImplSVWinData maWinData; // indepen data for Windows classes ImplSVWinData maWinData; // indepen data for Windows classes
......
...@@ -185,7 +185,6 @@ void Idle::Start() ...@@ -185,7 +185,6 @@ void Idle::Start()
// insert timer and start // insert timer and start
mpIdleData = new ImplIdleData; mpIdleData = new ImplIdleData;
mpIdleData->mpIdle = this; mpIdleData->mpIdle = this;
mpIdleData->mbDelete = false;
mpIdleData->mbInIdle = false; mpIdleData->mbInIdle = false;
// insert last due to SFX! // insert last due to SFX!
...@@ -202,14 +201,7 @@ void Idle::Start() ...@@ -202,14 +201,7 @@ void Idle::Start()
else else
pSVData->mpFirstIdleData = mpIdleData; pSVData->mpFirstIdleData = mpIdleData;
} }
else if( !mpIdleData->mpIdle ) // TODO: remove when guilty found mpIdleData->mbDelete = false;
{
OSL_FAIL( "Idle::Start() on a destroyed Idle!" );
}
else
{
mpIdleData->mbDelete = false;
}
} }
void Idle::Stop() void Idle::Stop()
......
...@@ -343,11 +343,8 @@ inline void ImplYield( bool i_bWait, bool i_bAllEvents ) ...@@ -343,11 +343,8 @@ inline void ImplYield( bool i_bWait, bool i_bAllEvents )
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
// run timers that have timed out // run timers that have timed out
if ( !pSVData->mbNoCallTimer ) while ( pSVData->mbNotAllTimerCalled )
{ Timer::ImplTimerCallbackProc();
while ( pSVData->mbNotAllTimerCalled )
Timer::ImplTimerCallbackProc();
}
//Process all idles //Process all idles
Idle::Idle::ProcessAllIdleHandlers(); Idle::Idle::ProcessAllIdleHandlers();
...@@ -368,7 +365,7 @@ inline void ImplYield( bool i_bWait, bool i_bAllEvents ) ...@@ -368,7 +365,7 @@ inline void ImplYield( bool i_bWait, bool i_bAllEvents )
// the system timer events will not necessarily come in non waiting mode // the system timer events will not necessarily come in non waiting mode
// e.g. on OS X; need to trigger timer checks manually // e.g. on OS X; need to trigger timer checks manually
if( pSVData->maAppData.mbNoYield && !pSVData->mbNoCallTimer ) if( pSVData->maAppData.mbNoYield )
{ {
do do
{ {
......
...@@ -117,33 +117,10 @@ void Timer::ImplTimerCallbackProc( bool idle ) ...@@ -117,33 +117,10 @@ void Timer::ImplTimerCallbackProc( bool idle )
sal_uLong nDeltaTime; sal_uLong nDeltaTime;
sal_uLong nTime = tools::Time::GetSystemTicks(); sal_uLong nTime = tools::Time::GetSystemTicks();
if ( pSVData->mbNoCallTimer )
return;
pSVData->mnTimerUpdate++; pSVData->mnTimerUpdate++;
pSVData->mbNotAllTimerCalled = true; pSVData->mbNotAllTimerCalled = true;
// find timer where the timer handler needs to be called Timer::CheckExpiredTimer(true);
pTimerData = pSVData->mpFirstTimerData;
while ( pTimerData )
{
// If the timer is not new, was not deleted, and if it is not in the timeout handler, then
// call the handler as soon as the time is up.
if ( (pTimerData->mnTimerUpdate < pSVData->mnTimerUpdate) &&
!pTimerData->mbDelete && !pTimerData->mbInTimeout)
{
// time has expired
if ( pTimerData->GetDeadline() <= nTime )
{
// set new update time
pTimerData->mnUpdateTime = nTime;
pTimerData->Invoke();
}
}
pTimerData = pTimerData->mpNext;
}
// determine new time // determine new time
sal_uLong nNewTime = tools::Time::GetSystemTicks(); sal_uLong nNewTime = tools::Time::GetSystemTicks();
...@@ -211,11 +188,17 @@ void Timer::ImplTimerCallbackProc( bool idle ) ...@@ -211,11 +188,17 @@ void Timer::ImplTimerCallbackProc( bool idle )
} }
bool Timer::TimerReady() bool Timer::TimerReady()
{
return Timer::CheckExpiredTimer(false);
}
bool Timer::CheckExpiredTimer(bool bDoInvoke)
{ {
// find timer where the timer handler needs to be called // find timer where the timer handler needs to be called
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
ImplTimerData* pTimerData = pSVData->mpFirstTimerData; ImplTimerData* pTimerData = pSVData->mpFirstTimerData;
sal_uLong nTime = tools::Time::GetSystemTicks(); sal_uLong nTime = tools::Time::GetSystemTicks();
bool timerExpired = false;
while ( pTimerData ) while ( pTimerData )
{ {
// If the timer is not new, was not deleted, and if it is not in the timeout handler, then // If the timer is not new, was not deleted, and if it is not in the timeout handler, then
...@@ -226,13 +209,19 @@ bool Timer::TimerReady() ...@@ -226,13 +209,19 @@ bool Timer::TimerReady()
// time has expired // time has expired
if ( pTimerData->GetDeadline() <= nTime ) if ( pTimerData->GetDeadline() <= nTime )
{ {
return true; if(bDoInvoke)
{
//Set new update Timer
pTimerData->mnUpdateTime = nTime;
pTimerData->Invoke();
}
timerExpired = true;
} }
} }
pTimerData = pTimerData->mpNext; pTimerData = pTimerData->mpNext;
} }
return false; return timerExpired;
} }
Timer::Timer(): Timer::Timer():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment