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.
This commit is contained in:
Chris Johns
2025-12-03 14:45:55 +11:00
committed by mdavidsaver
parent 6689c9ce1f
commit b4114589ff

View File

@@ -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<epicsMutex> U(G);