summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2021-06-27 12:55:42 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2021-06-27 18:06:33 +0200
commit642791720622618c9b66633c3e1224a4d340b167 (patch)
tree195c53b9f0c132ac1fc07f3db86df631af196408
parentde873f01d286d57829d8fb78d1f2748372552d37 (diff)
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@fbihome.de>
-rw-r--r--include/vcl/idle.hxx2
-rw-r--r--include/vcl/task.hxx13
-rw-r--r--include/vcl/timer.hxx8
-rw-r--r--vcl/source/app/idle.cxx7
-rw-r--r--vcl/source/app/scheduler.cxx5
-rw-r--r--vcl/source/app/timer.cxx7
6 files changed, 26 insertions, 16 deletions
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 )