Kaydet (Commit) 11ffb51b authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

Drop Task::ReadyForSchedule

All relevant information is also provided by UpdateMinPeriod and
the calculations were even duplicated. This also includes dropping
Scheduler::UpdateMinPeriod, as this is now reduced to a simple
comparison and assignment, as we simply ignore larger returned
sleep times.

Change-Id: I13852e3e63daead451bf7fcb98be9b1d44bd7abd
üst b4cc0f2d
...@@ -35,8 +35,8 @@ private: ...@@ -35,8 +35,8 @@ private:
sal_uInt64 GetTimeout() const = delete; sal_uInt64 GetTimeout() const = delete;
protected: protected:
virtual bool ReadyForSchedule( sal_uInt64 nTimeNow ) const override; virtual sal_uInt64 UpdateMinPeriod(
virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override; sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override;
Idle( bool bAuto, const sal_Char *pDebugName = nullptr ); Idle( bool bAuto, const sal_Char *pDebugName = nullptr );
......
...@@ -35,9 +35,6 @@ class VCL_DLLPUBLIC Scheduler final ...@@ -35,9 +35,6 @@ class VCL_DLLPUBLIC Scheduler final
static inline bool HasPendingTasks( const ImplSchedulerContext &rSchedCtx, static inline bool HasPendingTasks( const ImplSchedulerContext &rSchedCtx,
const sal_uInt64 nTime ); const sal_uInt64 nTime );
static inline void UpdateMinPeriod( ImplSchedulerData *pSchedulerData,
sal_uInt64 nTime, sal_uInt64 &nMinPeriod );
static inline void UpdateSystemTimer( ImplSchedulerContext &rSchedCtx, static inline void UpdateSystemTimer( ImplSchedulerContext &rSchedCtx,
sal_uInt64 nMinPeriod, sal_uInt64 nMinPeriod,
bool bForce, sal_uInt64 nTime ); bool bForce, sal_uInt64 nTime );
......
...@@ -56,11 +56,18 @@ protected: ...@@ -56,11 +56,18 @@ protected:
const ImplSchedulerData* GetSchedulerData() const { return mpSchedulerData; } const ImplSchedulerData* GetSchedulerData() const { return mpSchedulerData; }
virtual void SetDeletionFlags(); virtual void SetDeletionFlags();
/// Is this item ready to be dispatched at nTimeNow
virtual bool ReadyForSchedule( sal_uInt64 nTimeNow ) const = 0;
/** /**
* Adjust nMinPeriod downwards if we want to be notified before * How long (in MS) until the Task is ready to be dispatched?
* then, nTimeNow is the current time. *
* Simply return Scheduler::ImmediateTimeoutMs if you're ready, like an
* Idle. If you have to return Scheduler::InfiniteTimeoutMs, you probably
* need an other mechanism to wake up the Scheduler or rely on other
* Tasks to be scheduled, or simply use a polling Timer.
*
* @param nMinPeriod the currently expected sleep time
* @param nTimeNow the current time
* @return the sleep time of the Task to become ready
*/ */
virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const = 0; virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const = 0;
......
...@@ -31,8 +31,8 @@ class VCL_DLLPUBLIC Timer : public Task ...@@ -31,8 +31,8 @@ class VCL_DLLPUBLIC Timer : public Task
protected: protected:
virtual void SetDeletionFlags() override; virtual void SetDeletionFlags() override;
virtual bool ReadyForSchedule( sal_uInt64 nTimeNow ) const override; virtual sal_uInt64 UpdateMinPeriod(
virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override; sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override;
Timer( bool bAuto, const sal_Char *pDebugName = nullptr ); Timer( bool bAuto, const sal_Char *pDebugName = nullptr );
......
...@@ -55,11 +55,6 @@ void Idle::Start() ...@@ -55,11 +55,6 @@ void Idle::Start()
Task::StartTimer(nPeriod); Task::StartTimer(nPeriod);
} }
bool Idle::ReadyForSchedule( sal_uInt64 /* nTimeNow */ ) const
{
return true;
}
sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 /* nMinPeriod */, sal_uInt64 /* nTimeNow */ ) const sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 /* nMinPeriod */, sal_uInt64 /* nTimeNow */ ) const
{ {
return Scheduler::ImmediateTimeoutMs; return Scheduler::ImmediateTimeoutMs;
......
...@@ -172,19 +172,6 @@ bool Scheduler::GetDeterministicMode() ...@@ -172,19 +172,6 @@ bool Scheduler::GetDeterministicMode()
return g_bDeterministicMode; return g_bDeterministicMode;
} }
inline void Scheduler::UpdateMinPeriod( ImplSchedulerData * const pSchedulerData,
const sal_uInt64 nTime, sal_uInt64 &nMinPeriod )
{
if ( nMinPeriod > ImmediateTimeoutMs )
{
sal_uInt64 nCurPeriod = nMinPeriod;
nMinPeriod = pSchedulerData->mpTask->UpdateMinPeriod( nCurPeriod, nTime );
assert( nMinPeriod <= nCurPeriod );
if ( nCurPeriod < nMinPeriod )
nMinPeriod = nCurPeriod;
}
}
inline void Scheduler::UpdateSystemTimer( ImplSchedulerContext &rSchedCtx, inline void Scheduler::UpdateSystemTimer( ImplSchedulerContext &rSchedCtx,
const sal_uInt64 nMinPeriod, const sal_uInt64 nMinPeriod,
const bool bForce, const sal_uInt64 nTime ) const bool bForce, const sal_uInt64 nTime )
...@@ -254,6 +241,8 @@ bool Scheduler::ProcessTaskScheduling() ...@@ -254,6 +241,8 @@ bool Scheduler::ProcessTaskScheduling()
ImplSchedulerData *pMostUrgent = nullptr; ImplSchedulerData *pMostUrgent = nullptr;
ImplSchedulerData *pPrevMostUrgent = nullptr; ImplSchedulerData *pPrevMostUrgent = nullptr;
sal_uInt64 nMinPeriod = InfiniteTimeoutMs; sal_uInt64 nMinPeriod = InfiniteTimeoutMs;
sal_uInt64 nMostUrgentPeriod = InfiniteTimeoutMs;
sal_uInt64 nReadyPeriod = InfiniteTimeoutMs;
DBG_TESTSOLARMUTEX(); DBG_TESTSOLARMUTEX();
...@@ -298,16 +287,18 @@ bool Scheduler::ProcessTaskScheduling() ...@@ -298,16 +287,18 @@ bool Scheduler::ProcessTaskScheduling()
goto next_entry; goto next_entry;
// skip ready tasks with lower priority than the most urgent (numerical lower is higher) // skip ready tasks with lower priority than the most urgent (numerical lower is higher)
if ( pSchedulerData->mpTask->ReadyForSchedule( nTime ) && nReadyPeriod = pSchedulerData->mpTask->UpdateMinPeriod( nMinPeriod, nTime );
if ( ImmediateTimeoutMs == nReadyPeriod &&
(!pMostUrgent || (pSchedulerData->mpTask->GetPriority() < pMostUrgent->mpTask->GetPriority())) ) (!pMostUrgent || (pSchedulerData->mpTask->GetPriority() < pMostUrgent->mpTask->GetPriority())) )
{ {
if ( pMostUrgent ) if ( pMostUrgent && nMinPeriod > nMostUrgentPeriod )
UpdateMinPeriod( pMostUrgent, nTime, nMinPeriod ); nMinPeriod = nMostUrgentPeriod;
pPrevMostUrgent = pPrevSchedulerData; pPrevMostUrgent = pPrevSchedulerData;
pMostUrgent = pSchedulerData; pMostUrgent = pSchedulerData;
nMostUrgentPeriod = nReadyPeriod;
} }
else else if ( nMinPeriod > nReadyPeriod )
UpdateMinPeriod( pSchedulerData, nTime, nMinPeriod ); nMinPeriod = nReadyPeriod;
next_entry: next_entry:
pPrevSchedulerData = pSchedulerData; pPrevSchedulerData = pSchedulerData;
...@@ -360,7 +351,9 @@ next_entry: ...@@ -360,7 +351,9 @@ next_entry:
if ( pMostUrgent->mpTask && pMostUrgent->mpTask->IsActive() ) if ( pMostUrgent->mpTask && pMostUrgent->mpTask->IsActive() )
{ {
pMostUrgent->mnUpdateTime = nTime; pMostUrgent->mnUpdateTime = nTime;
UpdateMinPeriod( pMostUrgent, nTime, nMinPeriod ); nReadyPeriod = pMostUrgent->mpTask->UpdateMinPeriod( nMinPeriod, nTime );
if ( nMinPeriod > nReadyPeriod )
nMinPeriod = nReadyPeriod;
UpdateSystemTimer( rSchedCtx, nMinPeriod, false, nTime ); UpdateSystemTimer( rSchedCtx, nMinPeriod, false, nTime );
} }
} }
......
...@@ -30,21 +30,11 @@ void Timer::SetDeletionFlags() ...@@ -30,21 +30,11 @@ void Timer::SetDeletionFlags()
Task::SetDeletionFlags(); Task::SetDeletionFlags();
} }
bool Timer::ReadyForSchedule( sal_uInt64 nTimeNow ) const sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64, sal_uInt64 nTimeNow ) const
{
return (GetSchedulerData()->mnUpdateTime + mnTimeout) <= nTimeNow;
}
sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const
{ {
sal_uInt64 nWakeupTime = GetSchedulerData()->mnUpdateTime + mnTimeout; sal_uInt64 nWakeupTime = GetSchedulerData()->mnUpdateTime + mnTimeout;
if( nWakeupTime <= nTimeNow ) return ( nWakeupTime <= nTimeNow )
return Scheduler::ImmediateTimeoutMs; ? Scheduler::ImmediateTimeoutMs : nWakeupTime - nTimeNow;
else
{
sal_uInt64 nSleepTime = nWakeupTime - nTimeNow;
return ( nSleepTime < nMinPeriod ) ? nSleepTime : nMinPeriod;
}
} }
Timer::Timer( bool bAuto, const sal_Char *pDebugName ) Timer::Timer( bool bAuto, const sal_Char *pDebugName )
......
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