mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal,wpilib] Fix TimedRobot notifier race (#8445)
It was possible for the alarm to fire between the set alarm and ack, resulting in a hang on next wait. It's not possible to ack before set alarm due to a race in sim step timing, so the fix is to provide an atomic ack and set alarm; the easiest way to implement this in the API was to change ack to optionally also set the alarm again.
This commit is contained in:
@@ -35,16 +35,14 @@ void TimedRobot::StartCompetition() {
|
||||
auto callback = m_callbacks.pop();
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetNotifierAlarm(m_notifier, callback.expirationTime.count(), 0, true,
|
||||
&status);
|
||||
WPILIB_CheckErrorStatus(status, "UpdateNotifierAlarm");
|
||||
|
||||
// Acknowledge previous alarm after setting the next one to avoid a race
|
||||
// against getting the next notifier timeout in HALSIM StepTiming.
|
||||
if (first) {
|
||||
first = false;
|
||||
HAL_SetNotifierAlarm(m_notifier, callback.expirationTime.count(), 0, true,
|
||||
&status);
|
||||
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
|
||||
} else {
|
||||
HAL_AcknowledgeNotifierAlarm(m_notifier, &status);
|
||||
HAL_AcknowledgeNotifierAlarm(
|
||||
m_notifier, true, callback.expirationTime.count(), 0, true, &status);
|
||||
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifierAlarm");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user