Skip to content

Commit 3aa8df5

Browse files
authored
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
1 parent 9c217b1 commit 3aa8df5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cores/rp2040/wiring_private.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,22 @@ static std::map<pin_size_t, CBInfo> _map;
8787

8888
void _gpioInterruptDispatcher(uint gpio, uint32_t events) {
8989
(void) events;
90+
9091
// Only need to lock around the std::map check, not the whole IRQ callback
91-
CoreMutex m(&_irqMutex);
92-
if (m) {
93-
auto irq = _map.find(gpio);
94-
if (irq != _map.end()) {
95-
auto cb = irq->second;
96-
cb.callback();
92+
CBInfo *cb;
93+
{
94+
CoreMutex m(&_irqMutex);
95+
if (m) {
96+
auto irq = _map.find(gpio);
97+
if (irq == _map.end()) {
98+
return;
99+
}
100+
cb = &irq->second;
101+
} else {
102+
return;
97103
}
98104
}
105+
cb->callback();
99106
}
100107

101108
// To be called when appropriately protected w/IRQ and mutex protects

0 commit comments

Comments
 (0)