From 097f77cbcf7fee7e67199bdc37642b83bdeec03f Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Thu, 30 Apr 2026 15:21:42 -0500 Subject: [PATCH] Seitch to concurrency over std::mutex for platform agnostic behavior --- src/mesh/SerialHalDevice.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/mesh/SerialHalDevice.cpp b/src/mesh/SerialHalDevice.cpp index 6260941e4..3bb9bf5bd 100644 --- a/src/mesh/SerialHalDevice.cpp +++ b/src/mesh/SerialHalDevice.cpp @@ -8,12 +8,13 @@ #include #include #include -#include #include -#if defined(ARCH_ESP32) && defined(HW_SPI1_DEVICE) +#if defined(ARCH_ESP32) +#if defined(HW_SPI1_DEVICE) extern SPIClass SPI1; #endif +#endif namespace { @@ -31,7 +32,7 @@ struct InterruptSlot { volatile bool pending = false; }; -std::mutex interruptMutex; +concurrency::Lock interruptMutex; InterruptSlot interruptSlots[MAX_INTERRUPT_SLOTS]; StreamAPI *interruptStreamApi = nullptr; concurrency::Periodic *interruptEmitter = nullptr; @@ -102,7 +103,7 @@ void emitInterruptEvent(uint32_t pin, StreamAPI *streamApi) SerialHalDevice::emitResponse(event, streamApi); } -void markPendingBySlot(size_t slot) +void markPendingBySlot(uint8_t slot) { if (slot < MAX_INTERRUPT_SLOTS && interruptSlots[slot].used) { interruptSlots[slot].pending = true; @@ -151,7 +152,7 @@ int32_t pumpInterruptEvents() StreamAPI *streamApi = nullptr; { - std::lock_guard lock(interruptMutex); + concurrency::LockGuard lock(&interruptMutex); streamApi = interruptStreamApi; for (size_t i = 0; i < MAX_INTERRUPT_SLOTS; ++i) { if (interruptSlots[i].used && interruptSlots[i].pending) { @@ -273,7 +274,7 @@ void SerialHalDevice::handleAttachInterrupt(const meshtastic_SerialHalCommand &c int slot = -1; { - std::lock_guard lock(interruptMutex); + concurrency::LockGuard lock(&interruptMutex); slot = findSlotByPinLocked(cmd.pin); if (slot < 0) { slot = allocateSlotLocked(); @@ -302,7 +303,7 @@ void SerialHalDevice::handleDetachInterrupt(const meshtastic_SerialHalCommand &c ::detachInterrupt((int)cmd.pin); { - std::lock_guard lock(interruptMutex); + concurrency::LockGuard lock(&interruptMutex); const int slot = findSlotByPinLocked(cmd.pin); if (slot >= 0) { interruptSlots[slot] = InterruptSlot{}; @@ -374,7 +375,7 @@ void SerialHalDevice::emitResponse(const meshtastic_SerialHalResponse &response, // Keep a recent stream instance so async interrupt events can be emitted. { - std::lock_guard lock(interruptMutex); + concurrency::LockGuard lock(&interruptMutex); interruptStreamApi = streamApi; } }