From ac2f837c7ff49d1dfdcaa4ce9259560ea9dadc79 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 19:16:03 -1000 Subject: [PATCH] Use relaxed memory ordering for event pending flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The flag is just a hint — xQueueReceive with its own internal synchronization is the source of truth. Relaxed ordering avoids unnecessary fence cost on ESP targets. Worst case is missing an event for one loop iteration. --- esphome/components/wifi/wifi_component_esp_idf.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/esphome/components/wifi/wifi_component_esp_idf.cpp b/esphome/components/wifi/wifi_component_esp_idf.cpp index 22353bbd7f..3ad40709f0 100644 --- a/esphome/components/wifi/wifi_component_esp_idf.cpp +++ b/esphome/components/wifi/wifi_component_esp_idf.cpp @@ -145,7 +145,8 @@ void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, voi if (xQueueSend(s_event_queue, &to_send, 0L) != pdPASS) { delete to_send; // NOLINT(cppcoreguidelines-owning-memory) } else { - s_event_pending.store(1, std::memory_order_release); + // relaxed: this is just a hint; xQueueReceive is the source of truth + s_event_pending.store(1, std::memory_order_relaxed); } } @@ -734,7 +735,7 @@ const char *get_disconnect_reason_str(uint8_t reason) { void WiFiComponent::wifi_loop_() { // Fast path: skip xQueueReceive kernel call when no events are pending. // The atomic load is much cheaper than entering the FreeRTOS kernel. - if (s_event_pending.load(std::memory_order_acquire) == 0) + if (s_event_pending.load(std::memory_order_relaxed) == 0) return; // Clear flag before draining. If a new event arrives between the clear