From 3aa8df5ab730789f61d486bae665fd13b2b0921d Mon Sep 17 00:00:00 2001 From: Ikechukwu Ofili <62239576+ikeofilic1@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:37:24 -0500 Subject: [PATCH] GPIO interrupt dispatcher, minimize blocking (#2558) Only need to lock around the std::map check, not the whole IRQ callback This is important if you have a time sensitive interrupt on one of the cores --- cores/rp2040/wiring_private.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cores/rp2040/wiring_private.cpp b/cores/rp2040/wiring_private.cpp index a91b4f9..7498c28 100644 --- a/cores/rp2040/wiring_private.cpp +++ b/cores/rp2040/wiring_private.cpp @@ -87,15 +87,22 @@ static std::map _map; void _gpioInterruptDispatcher(uint gpio, uint32_t events) { (void) events; + // Only need to lock around the std::map check, not the whole IRQ callback - CoreMutex m(&_irqMutex); - if (m) { - auto irq = _map.find(gpio); - if (irq != _map.end()) { - auto cb = irq->second; - cb.callback(); + CBInfo *cb; + { + CoreMutex m(&_irqMutex); + if (m) { + auto irq = _map.find(gpio); + if (irq == _map.end()) { + return; + } + cb = &irq->second; + } else { + return; } } + cb->callback(); } // To be called when appropriately protected w/IRQ and mutex protects