mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] HALSIM_StepTiming: Avoid underflow (#8933)
Don't advance time if the only active timer is in the past; just wake up any notifiers.
This commit is contained in:
@@ -139,12 +139,20 @@ void HALSIM_StepTiming(uint64_t delta) {
|
||||
while (delta > 0) {
|
||||
uint64_t curTime = HAL_GetMonotonicTime();
|
||||
uint64_t nextTimeout = HALSIM_GetNextNotifierTimeout();
|
||||
uint64_t step = (std::min)(delta, nextTimeout - curTime);
|
||||
// If a notifier is already due, process it at the current simulated time
|
||||
// instead of underflowing nextTimeout - curTime.
|
||||
uint64_t step =
|
||||
nextTimeout <= curTime ? 0 : (std::min)(delta, nextTimeout - curTime);
|
||||
|
||||
StepTiming(step);
|
||||
delta -= step;
|
||||
|
||||
WakeupWaitNotifiers();
|
||||
|
||||
// Guard against notifiers that keep rearming at or before the same time.
|
||||
if (step == 0 && HALSIM_GetNextNotifierTimeout() <= curTime) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user