[socket] Fix RP2040 socket_delay race: don't clear wake flag before sleep

Restore the comment explaining why s_socket_woke must not be cleared
between the early-return check and the __wfe() loop, and restore the
s_socket_woke = false after the loop to consume the wake for the next
call. Both were lost during conflict resolution.
This commit is contained in:
J. Nick Koston
2026-03-14 16:09:24 -10:00
parent 0176305d24
commit 71da3dc2de
@@ -86,7 +86,9 @@ void socket_delay(uint32_t ms) {
s_socket_woke = false;
return;
}
s_socket_woke = false;
// Don't clear s_socket_woke here — if an IRQ fires between the check above
// and the while loop below, the while condition sees it immediately. Clearing
// here would lose that wake and sleep until the timer fires.
s_delay_expired = false;
// Set a one-shot timer to wake us after the timeout.
// add_alarm_in_ms returns >0 on success, 0 if time already passed, <0 on error.
@@ -104,6 +106,7 @@ void socket_delay(uint32_t ms) {
// Cancel timer if we woke early (socket data arrived before timeout)
if (!s_delay_expired)
cancel_alarm(alarm);
s_socket_woke = false; // consume the wake for next call
}
// No IRAM_ATTR equivalent needed: on RP2040, CYW43 async_context runs LWIP