[Libreoffice-commits] core.git: include/vcl vcl/source

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Sun Jun 27 16:07:05 UTC 2021


 include/vcl/idle.hxx         |    2 +-
 include/vcl/task.hxx         |   13 ++++++++++++-
 include/vcl/timer.hxx        |    8 +-------
 vcl/source/app/idle.cxx      |    7 ++++---
 vcl/source/app/scheduler.cxx |    5 ++++-
 vcl/source/app/timer.cxx     |    7 ++++---
 6 files changed, 26 insertions(+), 16 deletions(-)

New commits:
commit 642791720622618c9b66633c3e1224a4d340b167
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sun Jun 27 12:55:42 2021 +0200
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Sun Jun 27 18:06:33 2021 +0200

    Immediately schedule Tasks on start per default
    
    While writing a new Task, I was wondering, why it didn't schedule
    immediatly after calling Start(). Turned out Start() wasn't even
    calling Task::StartTimer(...) to trigger / wake up the Scheduler.
    
    So this changes Task's Start() to call StartTimer(0) to immediatly
    trigger the Scheduler at the end of Start(), but Tasks can opt out
    of it, if they aren't ready yet (like Timers).
    
    Change-Id: Ia2fdb45f502866c83f432b045e70bf27ccb61012
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117947
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/include/vcl/idle.hxx b/include/vcl/idle.hxx
index 78fcaae817b9..9abafae440d8 100644
--- a/include/vcl/idle.hxx
+++ b/include/vcl/idle.hxx
@@ -46,7 +46,7 @@ protected:
 public:
     Idle( const char *pDebugName = nullptr );
 
-    virtual void  Start() override;
+    virtual void Start(bool bStartTimer = true) override;
 };
 
 /**
diff --git a/include/vcl/task.hxx b/include/vcl/task.hxx
index e95aa5bc460a..3785e37fba53 100644
--- a/include/vcl/task.hxx
+++ b/include/vcl/task.hxx
@@ -85,7 +85,18 @@ public:
     // Call handler
     virtual void    Invoke() = 0;
 
-    virtual void    Start();
+    /**
+     * Schedules the task for execution
+     *
+     * If the timer is already active, it's reset!
+     * Check with Task::IsActive() to prevent reset.
+     *
+     * If you unset bStartTimer, the Task must call Task::StartTimer(...) to be correctly scheduled!
+     * Otherwise it might just be picked up when the Scheduler runs the next time.
+     *
+     * @param bStartTimer if false, don't schedule the Task by calling Task::StartTimer(0).
+     */
+    virtual void Start(bool bStartTimer = true);
     void            Stop();
 
     bool            IsActive() const { return mbActive; }
diff --git a/include/vcl/timer.hxx b/include/vcl/timer.hxx
index d9ad82ee5729..cd8733518093 100644
--- a/include/vcl/timer.hxx
+++ b/include/vcl/timer.hxx
@@ -58,13 +58,7 @@ public:
 
     void            SetTimeout( sal_uInt64 nTimeoutMs );
     sal_uInt64      GetTimeout() const { return mnTimeout; }
-    /**
-     * Activates the timer task
-     *
-     * If the timer is already active, it's reset!
-     * Check with Task::IsActive() to prevent reset.
-     */
-    virtual void    Start() override;
+    virtual void Start(bool bStartTimer = true) override;
 };
 
 /// 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 26e1e5f22210..7e5756537164 100644
--- a/vcl/source/app/idle.cxx
+++ b/vcl/source/app/idle.cxx
@@ -31,9 +31,9 @@ Idle::Idle( const char *pDebugName )
 {
 }
 
-void Idle::Start()
+void Idle::Start(const bool bStartTimer)
 {
-    Task::Start();
+    Task::Start(false);
 
     sal_uInt64 nPeriod = Scheduler::ImmediateTimeoutMs;
     if (Scheduler::GetDeterministicMode())
@@ -49,7 +49,8 @@ void Idle::Start()
         }
     }
 
-    Task::StartTimer(nPeriod);
+    if (bStartTimer)
+        Task::StartTimer(nPeriod);
 }
 
 sal_uInt64 Idle::UpdateMinPeriod( sal_uInt64 /* nTimeNow */ ) const
diff --git a/vcl/source/app/scheduler.cxx b/vcl/source/app/scheduler.cxx
index 735792cfc3e2..c6f3f6b737d4 100644
--- a/vcl/source/app/scheduler.cxx
+++ b/vcl/source/app/scheduler.cxx
@@ -542,7 +542,7 @@ void Task::SetDeletionFlags()
     mbActive = false;
 }
 
-void Task::Start()
+void Task::Start(const bool bStartTimer)
 {
     ImplSVData *const pSVData = ImplGetSVData();
     ImplSchedulerContext &rSchedCtx = pSVData->maSchedCtx;
@@ -582,6 +582,9 @@ void Task::Start()
                   << " " << mpSchedulerData << "  restarted  " << *this );
 
     mpSchedulerData->mnUpdateTime  = tools::Time::GetSystemTicks();
+
+    if (bStartTimer)
+        Task::StartTimer(0);
 }
 
 void Task::Stop()
diff --git a/vcl/source/app/timer.cxx b/vcl/source/app/timer.cxx
index 75a97d867195..183cd41a4e2b 100644
--- a/vcl/source/app/timer.cxx
+++ b/vcl/source/app/timer.cxx
@@ -80,10 +80,11 @@ void Timer::Invoke( Timer *arg )
     maInvokeHandler.Call( arg );
 }
 
-void Timer::Start()
+void Timer::Start(const bool bStartTimer)
 {
-    Task::Start();
-    Task::StartTimer( mnTimeout );
+    Task::Start(false);
+    if (bStartTimer)
+        Task::StartTimer(mnTimeout);
 }
 
 void Timer::SetTimeout( sal_uInt64 nNewTimeout )


More information about the Libreoffice-commits mailing list