summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-09-06 08:27:08 +0000
committerJan-Marek Glogowski <glogow@fbihome.de>2017-01-17 16:08:46 +0100
commit9ec3b1e1bfd38a7a26b8f22024b0d62f771fd5a5 (patch)
treec922f7cbe0688763a4fc5b69312e2cef1b48c88d
parent9e51007039770370182839846676b205f5c34c57 (diff)
Always schedule with the same time
No need to always update the time - scheduling should be fast! Change-Id: Ic4c01f5a5759ef4970f1385aab6ef93cd67f33b6
-rw-r--r--include/vcl/idle.hxx8
-rw-r--r--include/vcl/timer.hxx2
-rw-r--r--vcl/inc/saltimer.hxx2
-rw-r--r--vcl/source/app/idle.cxx2
-rw-r--r--vcl/source/app/scheduler.cxx17
-rw-r--r--vcl/source/app/timer.cxx26
6 files changed, 27 insertions, 30 deletions
diff --git a/include/vcl/idle.hxx b/include/vcl/idle.hxx
index 5585d994b8b7..5a33e2e70ba9 100644
--- a/include/vcl/idle.hxx
+++ b/include/vcl/idle.hxx
@@ -27,6 +27,11 @@ class VCL_DLLPUBLIC Idle : public Scheduler
{
Link<Idle *, void> maIdleHdl; // Callback Link
+protected:
+ virtual bool ReadyForSchedule( bool bTimerOnly, sal_uInt64 nTimeNow ) const override;
+ virtual bool IsIdle() const override;
+ virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override;
+
public:
Idle( const sal_Char *pDebugName = nullptr );
Idle( const Idle& rIdle );
@@ -38,9 +43,6 @@ public:
void SetIdleHdl( const Link<Idle *, void>& rLink ) { maIdleHdl = rLink; }
const Link<Idle *, void>& GetIdleHdl() const { return maIdleHdl; }
virtual void Invoke() override;
- virtual bool ReadyForSchedule( bool bTimerOnly, sal_uInt64 nTimeNow ) const override;
- virtual bool IsIdle() const override;
- virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const override;
Idle& operator=( const Idle& rIdle );
};
diff --git a/include/vcl/timer.hxx b/include/vcl/timer.hxx
index 0e32810b9d12..c1ede8c83caf 100644
--- a/include/vcl/timer.hxx
+++ b/include/vcl/timer.hxx
@@ -33,7 +33,7 @@ protected:
virtual void SetDeletionFlags() override;
virtual bool ReadyForSchedule( bool bTimerOnly, sal_uInt64 nTimeNow ) const override;
virtual bool IsIdle() const override;
- virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const override;
+ virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override;
public:
Timer( const sal_Char *pDebugName = nullptr );
diff --git a/vcl/inc/saltimer.hxx b/vcl/inc/saltimer.hxx
index 9a71eace286f..72b1eb8e14fa 100644
--- a/vcl/inc/saltimer.hxx
+++ b/vcl/inc/saltimer.hxx
@@ -70,7 +70,7 @@ struct ImplSchedulerData
void Invoke();
const char *GetDebugName() const;
- static ImplSchedulerData *GetMostImportantTask( bool bTimer );
+ static ImplSchedulerData *GetMostImportantTask( bool bTimerOnly, sal_uInt64 nTimeNow );
};
#endif // INCLUDED_VCL_INC_SALTIMER_HXX
diff --git a/vcl/source/app/idle.cxx b/vcl/source/app/idle.cxx
index 10a7a495a92f..faf499ed440b 100644
--- a/vcl/source/app/idle.cxx
+++ b/vcl/source/app/idle.cxx
@@ -74,7 +74,7 @@ bool Idle::IsIdle() const
return true;
}
-sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 /* nMinPeriod */, sal_uInt64 /* nTime */ ) const
+sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 /* nMinPeriod */, sal_uInt64 /* nTimeNow */ ) const
{
assert(false); // idles currently don't hit this.
return ImmediateTimeoutMs;
diff --git a/vcl/source/app/scheduler.cxx b/vcl/source/app/scheduler.cxx
index c9aa2b1b3c2d..cc4e14ac4a1d 100644
--- a/vcl/source/app/scheduler.cxx
+++ b/vcl/source/app/scheduler.cxx
@@ -49,12 +49,11 @@ void ImplSchedulerData::Invoke()
mbInScheduler = false;
}
-ImplSchedulerData *ImplSchedulerData::GetMostImportantTask( bool bTimerOnly )
+ImplSchedulerData *ImplSchedulerData::GetMostImportantTask( bool bTimerOnly, sal_uInt64 nTimeNow )
{
ImplSVData* pSVData = ImplGetSVData();
ImplSchedulerData *pMostUrgent = nullptr;
- sal_uInt64 nTimeNow = tools::Time::GetSystemTicks();
for ( ImplSchedulerData *pSchedulerData = pSVData->mpFirstSchedulerData; pSchedulerData; pSchedulerData = pSchedulerData->mpNext )
{
if ( !pSchedulerData->mpScheduler || pSchedulerData->mbDelete || pSchedulerData->mbInScheduler ||
@@ -173,13 +172,16 @@ void Scheduler::CallbackTaskScheduling(bool)
bool Scheduler::ProcessTaskScheduling( bool bTimerOnly )
{
+ ImplSchedulerData* pSchedulerData;
+ sal_uInt64 nTime = tools::Time::GetSystemTicks();
+
DBG_TESTSOLARMUTEX();
- if (ImplSchedulerData * pSchedulerData = ImplSchedulerData::GetMostImportantTask(bTimerOnly))
+ if ((pSchedulerData = ImplSchedulerData::GetMostImportantTask(bTimerOnly, nTime)))
{
SAL_INFO("vcl.schedule", "Invoke task " << pSchedulerData->GetDebugName());
- pSchedulerData->mnUpdateTime = tools::Time::GetSystemTicks();
+ pSchedulerData->mnUpdateTime = nTime;
pSchedulerData->Invoke();
return true;
}
@@ -243,6 +245,13 @@ sal_uInt64 Scheduler::CalculateMinimumTimeout( bool &bHasActiveIdles )
pSchedulerData->GetDebugName() <<
"' update min period from " << nOldMinPeriod <<
" to " << nMinPeriod);
+ assert( nMinPeriod <= nOldMinPeriod );
+ if ( nMinPeriod > nOldMinPeriod )
+ {
+ nMinPeriod = nOldMinPeriod;
+ SAL_WARN("vcl.schedule",
+ "New update min period > old period - using old");
+ }
}
else
{
diff --git a/vcl/source/app/timer.cxx b/vcl/source/app/timer.cxx
index accd92734746..aabfbb28a211 100644
--- a/vcl/source/app/timer.cxx
+++ b/vcl/source/app/timer.cxx
@@ -41,30 +41,16 @@ bool Timer::IsIdle() const
return false;
}
-sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const
+sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const
{
- sal_uInt64 nDeltaTime;
- //determine smallest time slot
- if( mpSchedulerData->mnUpdateTime == nTime )
- {
- nDeltaTime = mnTimeout;
- if( nDeltaTime < nMinPeriod )
- nMinPeriod = nDeltaTime;
- }
+ sal_uInt64 nWakeupTime = mpSchedulerData->mnUpdateTime + mnTimeout;
+ if( nWakeupTime <= nTimeNow )
+ return ImmediateTimeoutMs;
else
{
- nDeltaTime = mpSchedulerData->mnUpdateTime + mnTimeout;
- if( nDeltaTime < nTime )
- nMinPeriod = ImmediateTimeoutMs;
- else
- {
- nDeltaTime -= nTime;
- if( nDeltaTime < nMinPeriod )
- nMinPeriod = nDeltaTime;
- }
+ sal_uInt64 nSleepTime = nWakeupTime - nTimeNow;
+ return ( nSleepTime < nMinPeriod ) ? nSleepTime : nMinPeriod;
}
-
- return nMinPeriod;
}
Timer::Timer(const sal_Char *pDebugName) :