FIX: Preventing gcc from reordering playerCount and currentPlayerId set

This commit is contained in:
Rodrigo Alfonso 2025-02-04 06:08:51 -03:00
parent b7295b2443
commit e2e95f08ab
9 changed files with 48 additions and 1 deletions

View File

@ -341,7 +341,10 @@ class LinkCable {
}
auto response = LinkRawCable::getData();
LINK_BARRIER;
state.currentPlayerId = response.playerId;
LINK_BARRIER;
_state.IRQFlag = true;
_state.IRQTimeout = 0;
@ -365,7 +368,9 @@ class LinkCable {
}
}
LINK_BARRIER;
state.playerCount = newPlayerCount;
LINK_BARRIER;
LinkRawCable::setData(LINK_CABLE_NO_DATA);
@ -453,6 +458,7 @@ class LinkCable {
}
void resetState() {
LINK_BARRIER;
state.playerCount = 1;
state.currentPlayerId = 0;
@ -470,6 +476,7 @@ class LinkCable {
}
_state.IRQFlag = false;
_state.IRQTimeout = 0;
LINK_BARRIER;
}
void stop() {

View File

@ -1014,10 +1014,12 @@ class LinkCableMultiboot {
}
void resetState(Result newResult = Result::NONE) {
LINK_BARRIER;
state = State::STOPPED;
result = newResult;
fixedData = MultibootFixedData{};
dynamicData = MultibootDynamicData{};
LINK_BARRIER;
}
Response getAsyncResponse() {

View File

@ -230,6 +230,7 @@ class LinkCube {
}
void resetState() {
LINK_BARRIER;
needsClear = false;
newIncomingQueue.clear();
if (incomingQueue.isReading())
@ -240,6 +241,7 @@ class LinkCube {
resetFlag = false;
newIncomingQueue.overflow = false;
LINK_BARRIER;
}
void setPendingData() {

View File

@ -1561,6 +1561,7 @@ class LinkMobile {
}
void resetState() {
LINK_BARRIER;
setState(State::NEEDS_RESET);
adapterConfiguration = AdapterConfiguration{};
@ -1575,6 +1576,7 @@ class LinkMobile {
adapterType = AdapterType::UNKNOWN;
userRequests.syncClear();
LINK_BARRIER;
}
void stop() {

View File

@ -278,7 +278,10 @@ class LinkRawWireless {
return false;
}
LINK_BARRIER;
sessionState.currentPlayerId = systemStatus.currentPlayerId;
LINK_BARRIER;
_LRWLOG_("restored ok!");
isEnabled = true;
@ -336,11 +339,14 @@ class LinkRawWireless {
response.deviceId = Link::lsB32(status);
u8 slot = Link::lsB16(Link::msB32(status)) & 0b1111;
LINK_BARRIER;
response.currentPlayerId = slot == 0b0001 ? 1
: slot == 0b0010 ? 2
: slot == 0b0100 ? 3
: slot == 0b1000 ? 4
: 0;
LINK_BARRIER;
u8 adapterState = Link::msB16(Link::msB32(status));
response.isServerClosed = false;
@ -495,10 +501,12 @@ class LinkRawWireless {
}
}
LINK_BARRIER;
u8 oldPlayerCount = sessionState.playerCount;
sessionState.playerCount = 1 + response.connectedClientsSize;
if (sessionState.playerCount != oldPlayerCount)
_LRWLOG_("now: " + std::to_string(sessionState.playerCount) + " players");
LINK_BARRIER;
return true;
}
@ -522,10 +530,12 @@ class LinkRawWireless {
.clientNumber = (u8)Link::msB32(result.data[i])};
}
LINK_BARRIER;
u8 oldPlayerCount = sessionState.playerCount;
sessionState.playerCount = 1 + result.dataSize;
if (sessionState.playerCount != oldPlayerCount)
_LRWLOG_("now: " + std::to_string(sessionState.playerCount) + " players");
LINK_BARRIER;
return true;
}
@ -549,10 +559,12 @@ class LinkRawWireless {
.clientNumber = (u8)Link::msB32(result.data[i])};
}
LINK_BARRIER;
u8 oldPlayerCount = sessionState.playerCount;
sessionState.playerCount = 1 + result.dataSize;
if (sessionState.playerCount != oldPlayerCount)
_LRWLOG_("now: " + std::to_string(sessionState.playerCount) + " players");
LINK_BARRIER;
_LRWLOG_("server CLOSED");
sessionState.isServerClosed = true;
@ -706,8 +718,11 @@ class LinkRawWireless {
return false;
}
LINK_BARRIER;
u8 assignedPlayerId = 1 + (u8)status;
sessionState.currentPlayerId = assignedPlayerId;
LINK_BARRIER;
_LRWLOG_("state = CONNECTED");
state = State::CONNECTED;
@ -1117,12 +1132,14 @@ class LinkRawWireless {
* \warning This is internal API!
*/
void _resetState() {
LINK_BARRIER;
_LRWLOG_("state = NEEDS_RESET");
state = State::NEEDS_RESET;
asyncState = AsyncState::IDLE;
sessionState.playerCount = 1;
sessionState.currentPlayerId = 0;
sessionState.isServerClosed = false;
LINK_BARRIER;
}
/**

View File

@ -309,8 +309,10 @@ class LinkUART {
}
void resetState() {
LINK_BARRIER;
incomingQueue.clear();
outgoingQueue.clear();
LINK_BARRIER;
}
void stop() { setGeneralPurposeMode(); }

View File

@ -703,6 +703,7 @@ class LinkUniversal {
}
void resetState() {
LINK_BARRIER;
waitCount = 0;
switchWait =
SWITCH_WAIT_FRAMES + Link::_qran_range(1, SWITCH_WAIT_FRAMES_RANDOM);
@ -712,6 +713,7 @@ class LinkUniversal {
incomingMessages[i].clear();
incomingMessages[i].overflow = false;
}
LINK_BARRIER;
}
u32 safeStoi(const char* str) {

View File

@ -1080,8 +1080,10 @@ class LinkWireless {
}
if (players > linkRawWireless.sessionState.playerCount) {
LINK_BARRIER;
linkRawWireless.sessionState.playerCount =
Link::_min(players, config.maxPlayers);
LINK_BARRIER;
}
break;
@ -1351,9 +1353,12 @@ class LinkWireless {
}
// clients update their player count based on the transfer header
if (!isServer)
if (!isServer) {
LINK_BARRIER;
linkRawWireless.sessionState.playerCount =
LINK_WIRELESS_MIN_PLAYERS + header.playerCount;
LINK_BARRIER;
}
// clients can send their first message in the header itself
u32 currentPacketId = header.firstPacketId;
@ -1672,6 +1677,7 @@ class LinkWireless {
}
void resetState() {
LINK_BARRIER;
linkRawWireless._resetState();
sessionState.recvFlag = false;
@ -1705,6 +1711,7 @@ class LinkWireless {
sessionState.signalLevel = SignalLevel{};
isSendingSyncCommand = false;
LINK_BARRIER;
}
void stop() {

View File

@ -596,12 +596,14 @@ class LinkWirelessMultiboot {
}
void resetState() {
LINK_BARRIER;
progress.state = State::STOPPED;
progress.connectedClients = 0;
progress.percentage = 0;
progress.ready = &readyFlag;
readyFlag = false;
lastValidHeader = ClientHeader{};
LINK_BARRIER;
}
#ifdef LINK_WIRELESS_MULTIBOOT_ENABLE_LOGGING
@ -1072,8 +1074,10 @@ class LinkWirelessMultiboot {
if (!response->success)
return (void)stop(Result::FAILURE);
LINK_BARRIER;
u32 newConnectedClients = response->dataSize;
linkRawWireless.sessionState.playerCount = 1 + newConnectedClients;
LINK_BARRIER;
if (newConnectedClients > dynamicData.connectedClients) {
dynamicData.connectedClients = newConnectedClients;
@ -1433,11 +1437,13 @@ class LinkWirelessMultiboot {
}
void resetState(Result newResult = Result::NONE) {
LINK_BARRIER;
state = State::STOPPED;
result = newResult;
sendState = SendState::NOT_SENDING;
fixedData = MultibootFixedData{};
dynamicData = MultibootDynamicData{};
LINK_BARRIER;
}
bool stop(Result newResult = Result::NONE) {