From b4114589ffbfb9ca5091fdacc5c98f4d3daaf10d Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Wed, 3 Dec 2025 14:45:55 +1100 Subject: [PATCH] Skip any missed timer events updating the timer to now This stops a timer calling the callback for every missed event if the time jumps forward when corrected or moved. --- src/misc/timer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/misc/timer.cpp b/src/misc/timer.cpp index e3239eb..1dda328 100644 --- a/src/misc/timer.cpp +++ b/src/misc/timer.cpp @@ -118,6 +118,18 @@ void Timer::run() work->processing = true; queue.pop_front(); + if(work->period > 0.0 && alive && !work->cancelled) { + /* + * If the distance between the time now and the time + * the timer was to run is more than the period move + * the timer's run time to now and avoid the timer + * spinning issuing callbacks for missed timer events + */ + if ((now - work->timeToRun) > work->period) { + work->timeToRun = now; + } + } + { epicsGuardRelease U(G);