From a386fcc9f917cab08770027a5e5293ccf8faa1f8 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Sat, 3 Feb 2024 06:36:53 -0800 Subject: [PATCH] Fixes another (smaller) race condition in ESP32's select wakeup. The wakeup_from_isr routine consults the pendingWakeup_ and inSelect_ variables. These variables need to be locked, because multi-core ESP32's could run an isr on one core and othercode on a different core. Moves the atomic lock from esp_wakeup_from_isr into OSSelectWakeup::wakeup_from_isr. --- src/os/OSSelectWakeup.cxx | 1 - src/os/OSSelectWakeup.hxx | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/os/OSSelectWakeup.cxx b/src/os/OSSelectWakeup.cxx index 50efb44ac..d3ed3784f 100644 --- a/src/os/OSSelectWakeup.cxx +++ b/src/os/OSSelectWakeup.cxx @@ -240,7 +240,6 @@ void OSSelectWakeup::esp_wakeup() /// call from within an ISR context. void OSSelectWakeup::esp_wakeup_from_isr() { - AtomicHolder h(this); BaseType_t woken = pdFALSE; // If our VFS FD is not set in the except fd_set we can exit early. diff --git a/src/os/OSSelectWakeup.hxx b/src/os/OSSelectWakeup.hxx index 57f1ea708..ed45a6adf 100644 --- a/src/os/OSSelectWakeup.hxx +++ b/src/os/OSSelectWakeup.hxx @@ -159,6 +159,10 @@ public: #if OPENMRN_FEATURE_RTOS_FROM_ISR void wakeup_from_isr() { +#if defined(ESP_PLATFORM) + // On multi-core ESP32s we need to lock objects even in ISRs. + AtomicHolder h(this); +#endif pendingWakeup_ = true; if (inSelect_) {