include/vcl/idle.hxx | 4 +- include/vcl/scheduler.hxx | 17 +++++++-- include/vcl/timer.hxx | 8 +--- vcl/source/app/idle.cxx | 12 ++---- vcl/source/app/scheduler.cxx | 53 ++++++++++++++++++++--------- vcl/source/app/timer.cxx | 78 +++++++++++-------------------------------- 6 files changed, 79 insertions(+), 93 deletions(-)
New commits: commit 6d64d2f38d9f6c2f54e05675ecd0709eabf6d8ca Author: Ashod Nakashian <ashodnakash...@yahoo.com> Date: Sun Jul 19 19:40:18 2015 -0400 Minor refactoring and cleanup of Scheduler and Timer. Members are now const-correct. Replaced compile-time constants with enum. Refactored common functions from Timer to Scheduler. Disabled timer-precision unittests as they misfire often. These changes are non-functional. Change-Id: I6bb3d9fc402cadd556d9063ed9a4888f114c73d7 Reviewed-on: https://gerrit.libreoffice.org/17977 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Michael Meeks <michael.me...@collabora.com> Tested-by: Michael Meeks <michael.me...@collabora.com> diff --git a/include/vcl/idle.hxx b/include/vcl/idle.hxx index 2e853b7..df868f1 100644 --- a/include/vcl/idle.hxx +++ b/include/vcl/idle.hxx @@ -39,8 +39,8 @@ public: void SetIdleHdl( const Link<Idle *, void>& rLink ) { maIdleHdl = rLink; } const Link<Idle *, void>& GetIdleHdl() const { return maIdleHdl; } virtual void Invoke() SAL_OVERRIDE; - virtual bool ReadyForSchedule( bool bTimer ) SAL_OVERRIDE; - virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) SAL_OVERRIDE; + virtual bool ReadyForSchedule( bool bTimer ) const SAL_OVERRIDE; + virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const SAL_OVERRIDE; Idle& operator=( const Idle& rIdle ); }; diff --git a/include/vcl/scheduler.hxx b/include/vcl/scheduler.hxx index c4d0937..612bd08 100644 --- a/include/vcl/scheduler.hxx +++ b/include/vcl/scheduler.hxx @@ -51,23 +51,32 @@ enum class SchedulerPriority { class VCL_DLLPUBLIC Scheduler { +private: + static void InitSystemTimer(ImplSVData* pSVData); + protected: ImplSchedulerData* mpSchedulerData; /// Pointer to element in scheduler list const sal_Char *mpDebugName; /// Useful for debugging SchedulerPriority mePriority; /// Scheduler priority bool mbActive; /// Currently in the scheduler + // These should be constexpr static, when supported. + static const sal_uInt64 ImmediateTimeoutMs = 1; + static const sal_uInt64 MaximumTimeoutMs = SAL_MAX_UINT64; + + static void ImplStartTimer(sal_uInt64 nMS); + friend struct ImplSchedulerData; virtual void SetDeletionFlags(); - virtual bool ReadyForSchedule( bool bTimer ) = 0; - virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) = 0; + virtual bool ReadyForSchedule( bool bTimer ) const = 0; + virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const = 0; public: Scheduler( const sal_Char *pDebugName = NULL ); Scheduler( const Scheduler& rScheduler ); virtual ~Scheduler(); - void SetPriority( SchedulerPriority ePriority ); + void SetPriority(SchedulerPriority ePriority) { mePriority = ePriority; } SchedulerPriority GetPriority() const { return mePriority; } void SetDebugName( const sal_Char *pDebugName ) { mpDebugName = pDebugName; } @@ -80,7 +89,7 @@ public: bool IsActive() const { return mbActive; } - Scheduler& operator=( const Scheduler& rScheduler ); + Scheduler& operator=( const Scheduler& rScheduler ); static void ImplDeInitScheduler(); // Process one pending Timer with highhest priority diff --git a/include/vcl/timer.hxx b/include/vcl/timer.hxx index 8835291..220036b 100644 --- a/include/vcl/timer.hxx +++ b/include/vcl/timer.hxx @@ -31,11 +31,8 @@ protected: bool mbAuto; virtual void SetDeletionFlags() SAL_OVERRIDE; - virtual bool ReadyForSchedule( bool bTimer ) SAL_OVERRIDE; - virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) SAL_OVERRIDE; - -private: - static void InitSystemTimer(); + virtual bool ReadyForSchedule( bool bTimer ) const SAL_OVERRIDE; + virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const SAL_OVERRIDE; public: Timer( const sal_Char *pDebugName = NULL ); @@ -51,7 +48,6 @@ public: void Timeout() { Invoke(); } Timer& operator=( const Timer& rTimer ); virtual void Start() SAL_OVERRIDE; - static void ImplStartTimer( ImplSVData* pSVData, sal_uInt64 nMS ); }; /// An auto-timer is a multi-shot timer re-emitting itself at diff --git a/vcl/source/app/idle.cxx b/vcl/source/app/idle.cxx index 901c44e..6929d62 100644 --- a/vcl/source/app/idle.cxx +++ b/vcl/source/app/idle.cxx @@ -18,8 +18,6 @@ */ #include <vcl/idle.hxx> -#include <vcl/timer.hxx> -#include "svdata.hxx" void Idle::Invoke() { @@ -45,11 +43,10 @@ Idle::Idle( const Idle& rIdle ) : Scheduler(rIdle) void Idle::Start() { Scheduler::Start(); - ImplSVData* pSVData = ImplGetSVData(); - Timer::ImplStartTimer( pSVData, 0 ); + Scheduler::ImplStartTimer(Scheduler::ImmediateTimeoutMs); } -bool Idle::ReadyForSchedule( bool bTimer ) +bool Idle::ReadyForSchedule( bool bTimer ) const { // tdf#91727 - We need to re-work this to allow only UI idle handlers // and not timeouts to be processed in some limited scenarios @@ -57,14 +54,14 @@ bool Idle::ReadyForSchedule( bool bTimer ) return true; // !bTimer } -sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 /* nTime */ ) +sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 /* nTime */ ) const { switch (mePriority) { case SchedulerPriority::HIGHEST: case SchedulerPriority::HIGH: case SchedulerPriority::RESIZE: case SchedulerPriority::REPAINT: - nMinPeriod = 1; // don't wait. + nMinPeriod = ImmediateTimeoutMs; // don't wait. break; default: // FIXME: tdf#92036 workaround, I should be 1 too - wait 5ms @@ -75,5 +72,4 @@ sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 /* nTime */ return nMinPeriod; } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/app/scheduler.cxx b/vcl/source/app/scheduler.cxx index 4cbeeb9..b8849a1 100644 --- a/vcl/source/app/scheduler.cxx +++ b/vcl/source/app/scheduler.cxx @@ -20,10 +20,9 @@ #include <svdata.hxx> #include <tools/time.hxx> #include <vcl/scheduler.hxx> -#include <vcl/timer.hxx> #include <saltimer.hxx> - -#define MAX_TIMER_PERIOD SAL_MAX_UINT64 +#include <svdata.hxx> +#include <salinst.hxx> void ImplSchedulerData::Invoke() { @@ -97,14 +96,44 @@ void Scheduler::ImplDeInitScheduler() } while ( pSchedulerData ); - pSVData->mpFirstSchedulerData = NULL; - pSVData->mnTimerPeriod = 0; + pSVData->mpFirstSchedulerData = NULL; + pSVData->mnTimerPeriod = 0; } delete pSVData->mpSalTimer; pSVData->mpSalTimer = 0; } +void Scheduler::ImplStartTimer(sal_uInt64 nMS) +{ + ImplSVData* pSVData = ImplGetSVData(); + InitSystemTimer(pSVData); + + // Update timeout only when not in timer handler and + // only if smaller timeout, to avoid skipping. + if (!pSVData->mnUpdateStack && + nMS < pSVData->mnTimerPeriod) + { + pSVData->mnTimerPeriod = nMS; + pSVData->mpSalTimer->Start(nMS); + } +} + +/** +* Initialize the platform specific timer on which all the +* platform independent timers are built +*/ +void Scheduler::InitSystemTimer(ImplSVData* pSVData) +{ + assert(pSVData != nullptr); + if (!pSVData->mpSalTimer) + { + pSVData->mnTimerPeriod = MaximumTimeoutMs; + pSVData->mpSalTimer = pSVData->mpDefInst->CreateSalTimer(); + pSVData->mpSalTimer->SetCallback(CallbackTaskScheduling); + } +} + void Scheduler::CallbackTaskScheduling(bool ignore) { // this function is for the saltimer callback @@ -120,7 +149,7 @@ void Scheduler::ProcessTaskScheduling( bool bTimer ) ImplSchedulerData* pPrevSchedulerData = NULL; ImplSVData* pSVData = ImplGetSVData(); sal_uInt64 nTime = tools::Time::GetSystemTicks(); - sal_uInt64 nMinPeriod = MAX_TIMER_PERIOD; + sal_uInt64 nMinPeriod = MaximumTimeoutMs; pSVData->mnUpdateStack++; // tdf#91727 - NB. bTimer is ultimately not used @@ -165,20 +194,15 @@ void Scheduler::ProcessTaskScheduling( bool bTimer ) { if ( pSVData->mpSalTimer ) pSVData->mpSalTimer->Stop(); - pSVData->mnTimerPeriod = MAX_TIMER_PERIOD; + pSVData->mnTimerPeriod = MaximumTimeoutMs; } else { - Timer::ImplStartTimer( pSVData, nMinPeriod ); + Scheduler::ImplStartTimer(nMinPeriod); } pSVData->mnUpdateStack--; } -void Scheduler::SetPriority( SchedulerPriority ePriority ) -{ - mePriority = ePriority; -} - void Scheduler::Start() { // Mark timer active @@ -224,7 +248,7 @@ Scheduler& Scheduler::operator=( const Scheduler& rScheduler ) if ( IsActive() ) Stop(); - mbActive = false; + mbActive = false; mePriority = rScheduler.mePriority; if ( rScheduler.IsActive() ) @@ -259,4 +283,3 @@ Scheduler::~Scheduler() mpSchedulerData->mpScheduler = NULL; } } - diff --git a/vcl/source/app/timer.cxx b/vcl/source/app/timer.cxx index 7d92283..b048504 100644 --- a/vcl/source/app/timer.cxx +++ b/vcl/source/app/timer.cxx @@ -19,46 +19,26 @@ #include <tools/time.hxx> #include <vcl/timer.hxx> -#include <saltimer.hxx> -#include <svdata.hxx> -#include <salinst.hxx> -#define MAX_TIMER_PERIOD SAL_MAX_UINT64 - -void Timer::ImplStartTimer( ImplSVData* pSVData, sal_uInt64 nMS ) +void Timer::SetDeletionFlags() { - InitSystemTimer(); - - if ( !nMS ) - nMS = 1; - - // Assume underlying timers are recurring timers, if same period - just wait. - if ( nMS != pSVData->mnTimerPeriod ) + // If no AutoTimer, then stop. + if ( !mbAuto ) { - pSVData->mnTimerPeriod = nMS; - pSVData->mpSalTimer->Start( nMS ); + mpSchedulerData->mbDelete = true; + mbActive = false; } } -void Timer::SetDeletionFlags() -{ - // if no AutoTimer than stop - if ( !mbAuto ) - { - mpSchedulerData->mbDelete = true; - mbActive = false; - } -} - -bool Timer::ReadyForSchedule( bool bTimer ) +bool Timer::ReadyForSchedule( bool bTimer ) const { (void)bTimer; return (mpSchedulerData->mnUpdateTime + mnTimeout) <= tools::Time::GetSystemTicks(); } -sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) +sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const { - sal_uInt64 nNewTime = tools::Time::GetSystemTicks(); + const sal_uInt64 nNewTime = tools::Time::GetSystemTicks(); sal_uInt64 nDeltaTime; //determine smallest time slot if( mpSchedulerData->mnUpdateTime == nTime ) @@ -71,7 +51,7 @@ sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) { nDeltaTime = mpSchedulerData->mnUpdateTime + mnTimeout; if( nDeltaTime < nNewTime ) - nMinPeriod = 1; + nMinPeriod = ImmediateTimeoutMs; else { nDeltaTime -= nNewTime; @@ -83,32 +63,19 @@ sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) return nMinPeriod; } -/** - * Initialize the platform specific timer on which all the - * platform independent timers are built - */ -void Timer::InitSystemTimer() +Timer::Timer(const sal_Char *pDebugName) : + Scheduler(pDebugName), + mnTimeout(ImmediateTimeoutMs), + mbAuto(false) { - ImplSVData* pSVData = ImplGetSVData(); - if( ! pSVData->mpSalTimer ) - { - pSVData->mnTimerPeriod = MAX_TIMER_PERIOD; - pSVData->mpSalTimer = pSVData->mpDefInst->CreateSalTimer(); - pSVData->mpSalTimer->SetCallback( CallbackTaskScheduling ); - } -} - -Timer::Timer(const sal_Char *pDebugName) : Scheduler(pDebugName) -{ - mnTimeout = 1; - mbAuto = false; mePriority = SchedulerPriority::HIGHEST; } -Timer::Timer( const Timer& rTimer ) : Scheduler(rTimer) +Timer::Timer( const Timer& rTimer ) : + Scheduler(rTimer), + mnTimeout(rTimer.mnTimeout), + mbAuto(rTimer.mbAuto) { - mnTimeout = rTimer.mnTimeout; - mbAuto = rTimer.mbAuto; maTimeoutHdl = rTimer.maTimeoutHdl; } @@ -120,21 +87,16 @@ void Timer::Invoke() void Timer::Start() { Scheduler::Start(); - - ImplSVData* pSVData = ImplGetSVData(); - if ( mnTimeout < pSVData->mnTimerPeriod ) - Timer::ImplStartTimer( pSVData, mnTimeout ); + Scheduler::ImplStartTimer(mnTimeout); } void Timer::SetTimeout( sal_uInt64 nNewTimeout ) { mnTimeout = nNewTimeout; - // if timer is active then renew clock + // If timer is active, then renew clock. if ( mbActive ) { - ImplSVData* pSVData = ImplGetSVData(); - if ( !pSVData->mnUpdateStack && (mnTimeout < pSVData->mnTimerPeriod) ) - Timer::ImplStartTimer( pSVData, mnTimeout ); + Scheduler::ImplStartTimer(mnTimeout); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits