[Libreoffice-commits] core.git: Branch 'feature/priorities' - include/vcl vcl/source
Jennifer Liebel
jliebel94 at gmail.com
Thu Oct 30 06:49:33 PDT 2014
include/vcl/timer.hxx | 2 +-
vcl/source/app/timer.cxx | 32 ++++++++++++++++++++++----------
2 files changed, 23 insertions(+), 11 deletions(-)
New commits:
commit b5d780f20aaa9f70bf53adde32bcb10ec57e171c
Author: Jennifer Liebel <jliebel94 at gmail.com>
Date: Thu Oct 30 13:46:44 2014 +0000
commented and formated
Change-Id: I6d2c51ceaca8662e3b6d47ceeecbc45d0109d0df
diff --git a/include/vcl/timer.hxx b/include/vcl/timer.hxx
index 1fec77d..f7ab003 100644
--- a/include/vcl/timer.hxx
+++ b/include/vcl/timer.hxx
@@ -43,9 +43,9 @@ class VCL_DLLPUBLIC Timer
{
protected:
ImplTimerData* mpTimerData;
+ sal_uLong mnTimeout;
sal_Int32 mnDefaultPriority;
sal_Int32 mnPriority;
- sal_uLong mnTimeout;
bool mbActive;
bool mbAuto;
Link maTimeoutHdl;
diff --git a/vcl/source/app/timer.cxx b/vcl/source/app/timer.cxx
index bad6c1b..c4f0b45 100644
--- a/vcl/source/app/timer.cxx
+++ b/vcl/source/app/timer.cxx
@@ -97,7 +97,6 @@ void Timer::ImplTimerCallbackProc()
sal_uLong nMinPeriod = MAX_TIMER_PERIOD;
sal_uLong nDeltaTime;
sal_uLong nTime = tools::Time::GetSystemTicks();
- bool bAllTimerCalled = true;
if ( pSVData->mbNoCallTimer )
return;
@@ -107,6 +106,7 @@ void Timer::ImplTimerCallbackProc()
pTimerData = pSVData->mpFirstTimerData;
pPrioFirstTimerData = NULL;
+ //running through the new incoming timers
while ( pTimerData )
{
// If the timer is not new, was not deleted, and if it is not in the timeout handler, then
@@ -115,20 +115,26 @@ void Timer::ImplTimerCallbackProc()
!pTimerData->mbDelete && !pTimerData->mbInTimeout )
{
// time has expired
- if ( (pTimerData->mnUpdateTime+pTimerData->mpTimer->mnTimeout) <= nTime || pTimerData->mpTimer->GetPriority() < pTimerData->mpTimer->GetDefaultPriority() )
+ if ( (pTimerData->mnUpdateTime+pTimerData->mpTimer->mnTimeout) <= nTime ||
+ pTimerData->mpTimer->GetPriority() < pTimerData->mpTimer->GetDefaultPriority() )
{
+ // increase priority to avoid starvation (higher priority means lower number)
pTimerData->mpTimer->SetPriority(pTimerData->mpTimer->GetPriority() - 1);
ImplTimerData* pCurrentTimer = pPrioFirstTimerData;
pPrevTimerData = NULL;
- if(pCurrentTimer != pTimerData){
+ if(pCurrentTimer != pTimerData)
+ {
//while the priority (number) of the new timer is greater than the priority
//of the current timer go to forward
- while(pCurrentTimer && pCurrentTimer->mpTimer && pCurrentTimer->mpTimer->GetPriority() <= pTimerData->mpTimer->GetPriority()){
+ while(pCurrentTimer && pCurrentTimer->mpTimer &&
+ pCurrentTimer->mpTimer->GetPriority() <= pTimerData->mpTimer->GetPriority())
+ {
pPrevTimerData = pCurrentTimer;
pCurrentTimer = pCurrentTimer->mpPrioNext;
}
//if there is no previous timer: the new timer is the first timer in the list
- if(!pPrevTimerData){
+ if(!pPrevTimerData)
+ {
if(pCurrentTimer && pCurrentTimer->mpTimer)
pTimerData->mpPrioNext = pCurrentTimer;
else
@@ -136,7 +142,8 @@ void Timer::ImplTimerCallbackProc()
pCurrentTimer = pTimerData;
}
//else the new timer is inserted in the middle or in the end of the list
- else{
+ else
+ {
pPrevTimerData->mpPrioNext = pTimerData;
if(pCurrentTimer && pCurrentTimer->mpTimer)
pTimerData->mpPrioNext = pCurrentTimer;
@@ -154,7 +161,9 @@ void Timer::ImplTimerCallbackProc()
if(pPrioFirstTimerData && pPrioFirstTimerData->mpTimer)
nPrevPrio = pPrioFirstTimerData->mpTimer->GetPriority();
- while(pPrioFirstTimerData && pPrioFirstTimerData->mpTimer && pPrioFirstTimerData->mpTimer->GetPriority() == nPrevPrio){
+ // running through the sorted list and call the timers with the highest priorities
+ while(pPrioFirstTimerData && pPrioFirstTimerData->mpTimer && pPrioFirstTimerData->mpTimer->GetPriority() == nPrevPrio)
+ {
// set new update time
pPrioFirstTimerData->mnUpdateTime = nTime;
nPrevPrio = pPrioFirstTimerData->mpTimer->GetPriority();
@@ -168,6 +177,8 @@ void Timer::ImplTimerCallbackProc()
// call Timeout
pPrioFirstTimerData->mbInTimeout = true;
pPrioFirstTimerData->mpTimer->Timeout();
+
+ //reset priority if the timer was called
if(pPrioFirstTimerData->mpTimer)
pPrioFirstTimerData->mpTimer->SetPriority( pPrioFirstTimerData->mpTimer->GetDefaultPriority() );
pPrioFirstTimerData->mbInTimeout = false;
@@ -176,11 +187,12 @@ void Timer::ImplTimerCallbackProc()
pPrevTimerData->mpPrioNext = NULL;
}
- while(pPrioFirstTimerData && pPrioFirstTimerData->mpTimer){
+ // resets the sorted list with the remaining timers which weren't called yet
+ while(pPrioFirstTimerData && pPrioFirstTimerData->mpTimer)
+ {
pPrevTimerData = pPrioFirstTimerData;
pPrioFirstTimerData = pPrioFirstTimerData->mpPrioNext;
pPrevTimerData->mpPrioNext = NULL;
- bAllTimerCalled = false;
}
// determine new time
@@ -245,7 +257,6 @@ void Timer::ImplTimerCallbackProc()
ImplStartTimer( pSVData, nMinPeriod );
pSVData->mnTimerUpdate--;
- //if(bAllTimerCalled)
pSVData->mbNotAllTimerCalled = false;
}
@@ -290,6 +301,7 @@ void Timer::SetTimeout( sal_uLong nNewTimeout)
{
mnTimeout = nNewTimeout;
+ //grade the timers
if(nNewTimeout==0)
mnPriority = IdlePriority::VCL_IDLE_PRIORITY_HIGHEST;
else if(nNewTimeout==1)
More information about the Libreoffice-commits
mailing list