Fix LibreTiny ISR safety: use vTaskNotifyGiveFromISR in wake_loop_any_context, update stale comment

This commit is contained in:
J. Nick Koston
2026-04-04 12:59:34 -10:00
parent 619370170c
commit 670a23b4c1
2 changed files with 14 additions and 7 deletions
+5 -5
View File
@@ -63,12 +63,12 @@
//
// Shared state and safety rationale:
//
// esphome_main_task_handle (TaskHandle_t, 4 bytes):
// Written once by main loop in init(). Read by TCP/IP thread (in callback)
// and background tasks (in wake).
// Safe: write-once-then-read pattern. Socket hooks may run before init(),
// esphome_main_task_handle (TaskHandle_t, 4 bytes, defined in main_task.c):
// Written once by main loop in Application::setup(). Read by TCP/IP thread
// (in callback) and background tasks (in wake).
// Safe: write-once-then-read pattern. Socket hooks may run before setup(),
// but the NULL check on esphome_main_task_handle in the callback provides correct
// degraded behavior — notifications are simply skipped until init() completes.
// degraded behavior — notifications are simply skipped until setup() completes.
//
// s_original_callback (netconn_callback, 4-byte function pointer):
// Written by main loop in hook_socket() (only when NULL — set once).
+9 -2
View File
@@ -34,8 +34,15 @@ void wake_loop_isrsafe(int *px_higher_priority_task_woken);
/// IRAM_ATTR entry point — defined in wake.cpp.
void wake_loop_any_context();
#else
/// LibreTiny: no working IRAM_ATTR, no ISR callers.
inline void wake_loop_any_context() { esphome_main_task_notify(); }
/// LibreTiny: GPIO ISRs are real hardware interrupts, so use ISR-safe API.
/// vTaskNotifyGiveFromISR is safe from both ISR and task context on ARM Cortex-M.
inline void wake_loop_any_context() {
if (esphome_main_task_handle != NULL) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(esphome_main_task_handle, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
#endif
inline void wake_loop_threadsafe() { esphome_main_task_notify(); }