Timer: actually support non-periodic timers

This commit is contained in:
Alexander A. Klimov 2023-01-03 13:37:15 +01:00
parent 3933502739
commit 298f3b1973
1 changed files with 7 additions and 2 deletions

View File

@ -168,7 +168,7 @@ void Timer::Start()
InitializeThread();
}
InternalRescheduleUnlocked(false);
InternalRescheduleUnlocked(false, m_Interval > 0 ? -1 : m_Next);
}
/**
@ -251,7 +251,7 @@ double Timer::GetNext() const
}
/**
* Adjusts all timers by adding the specified amount of time to their
* Adjusts all periodic timers by adding the specified amount of time to their
* next scheduled timestamp.
*
* @param adjustment The adjustment.
@ -268,6 +268,11 @@ void Timer::AdjustTimers(double adjustment)
std::vector<Timer *> timers;
for (Timer *timer : idx) {
/* Don't schedule the next call if this is not a periodic timer. */
if (timer->m_Interval <= 0) {
continue;
}
if (std::fabs(now - (timer->m_Next + adjustment)) <
std::fabs(now - timer->m_Next)) {
timer->m_Next += adjustment;