From 9ec9a526f5a4cf9ba0340e36f34a09546189ffea Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 3 Dec 2025 18:23:59 -0800 Subject: [PATCH] revise Timer phase reset --- src/misc/timer.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/misc/timer.cpp b/src/misc/timer.cpp index 1dda328..4990051 100644 --- a/src/misc/timer.cpp +++ b/src/misc/timer.cpp @@ -118,18 +118,6 @@ 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); @@ -139,6 +127,12 @@ void Timer::run() work->processing = false; if(work->period > 0.0 && alive && !work->cancelled) { + if(waitfor <= -work->period) { + // Periodic timer phase has fallen behind by at least one full period. + // Could be due to previous slow jobs, or a system time jump forward. + // Reset the phase. + work->timeToRun = now = epicsTime::getCurrent(); + } work->timeToRun += work->period; addElement(work); }