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
This commit is contained in:
Ikechukwu Ofili 2024-10-26 15:37:24 -05:00 committed by GitHub
parent 9c217b13df
commit 3aa8df5ab7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -87,15 +87,22 @@ static std::map<pin_size_t, CBInfo> _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