mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Change hal sim to use spinlocks (#1291)
This makes callback registration completely thread safe. This patch also uses templates and macros to dramatically reduce the amount of manual boilerplate.
This commit is contained in:
@@ -66,10 +66,10 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
|
||||
|
||||
port->fwd = false; // set to reverse
|
||||
|
||||
SimRelayData[channel].SetInitializedReverse(true);
|
||||
SimRelayData[channel].initializedReverse = true;
|
||||
} else {
|
||||
port->fwd = true; // set to forward
|
||||
SimRelayData[channel].SetInitializedForward(true);
|
||||
SimRelayData[channel].initializedForward = true;
|
||||
}
|
||||
|
||||
port->channel = static_cast<uint8_t>(channel);
|
||||
@@ -82,9 +82,9 @@ void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle) {
|
||||
relayHandles->Free(relayPortHandle);
|
||||
if (port == nullptr) return;
|
||||
if (port->fwd)
|
||||
SimRelayData[port->channel].SetInitializedForward(false);
|
||||
SimRelayData[port->channel].initializedForward = false;
|
||||
else
|
||||
SimRelayData[port->channel].SetInitializedReverse(false);
|
||||
SimRelayData[port->channel].initializedReverse = false;
|
||||
}
|
||||
|
||||
HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
|
||||
@@ -102,9 +102,9 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
|
||||
return;
|
||||
}
|
||||
if (port->fwd)
|
||||
SimRelayData[port->channel].SetForward(on);
|
||||
SimRelayData[port->channel].forward = on;
|
||||
else
|
||||
SimRelayData[port->channel].SetReverse(on);
|
||||
SimRelayData[port->channel].reverse = on;
|
||||
}
|
||||
|
||||
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
|
||||
@@ -114,8 +114,8 @@ HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
|
||||
return false;
|
||||
}
|
||||
if (port->fwd)
|
||||
return SimRelayData[port->channel].GetForward();
|
||||
return SimRelayData[port->channel].forward;
|
||||
else
|
||||
return SimRelayData[port->channel].GetReverse();
|
||||
return SimRelayData[port->channel].reverse;
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user