From 843b63edb433d38ca4386e09c04d4b0c0d81e52a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 4 Apr 2026 10:53:15 -1000 Subject: [PATCH] Move host wake_loop_threadsafe from application.cpp to wake.cpp --- esphome/core/application.cpp | 13 +------------ esphome/core/wake.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index 3df82e25a5..c04482c5d2 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -676,18 +676,7 @@ void Application::setup_wake_loop_threadsafe_() { } } -void wake_loop_threadsafe() { - // Wakes up lwip_select() in main loop by writing to connected loopback socket - if (App.wake_socket_fd_ >= 0) { - const char dummy = 1; - // Non-blocking send - if it fails (unlikely), select() will wake on timeout anyway - // No error checking needed: we control both ends of this loopback socket. - // This is safe to call from FreeRTOS tasks - send() is thread-safe in lwip - // Socket is already connected to loopback address, so send() is faster than sendto() - lwip_send(App.wake_socket_fd_, &dummy, 1, 0); - } -} -#endif // host wake_loop_threadsafe +#endif // USE_SOCKET_SELECT_SUPPORT void Application::get_build_time_string(std::span buffer) { ESPHOME_strncpy_P(buffer.data(), ESPHOME_BUILD_TIME_STR, buffer.size()); diff --git a/esphome/core/wake.cpp b/esphome/core/wake.cpp index c172a26ab7..cc2b4734f7 100644 --- a/esphome/core/wake.cpp +++ b/esphome/core/wake.cpp @@ -84,6 +84,18 @@ void wakeable_delay(uint32_t ms) { #endif // USE_RP2040 -// Host platform wake_loop_threadsafe() is in application.cpp (needs App.wake_socket_fd_) +// === Host (UDP loopback socket) === +#ifdef USE_SOCKET_SELECT_SUPPORT +#include "esphome/core/application.h" +#include + +void wake_loop_threadsafe() { + // Wakes up lwip_select() in main loop by writing to connected loopback socket + if (App.wake_socket_fd_ >= 0) { + const char dummy = 1; + lwip_send(App.wake_socket_fd_, &dummy, 1, 0); + } +} +#endif // USE_SOCKET_SELECT_SUPPORT } // namespace esphome