summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/utils/mpirq.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/utils/mpirq.c b/lib/utils/mpirq.c
index d04fab68b..8de13b0b6 100644
--- a/lib/utils/mpirq.c
+++ b/lib/utils/mpirq.c
@@ -62,8 +62,10 @@ mp_irq_obj_t *mp_irq_new(const mp_irq_methods_t *methods, mp_obj_t parent) {
void mp_irq_handler(mp_irq_obj_t *self) {
if (self->handler != mp_const_none) {
if (self->ishard) {
- // When executing code within a handler we must lock the GC to prevent
- // any memory allocations.
+ // When executing code within a handler we must lock the scheduler to
+ // prevent any scheduled callbacks from running, and lock the GC to
+ // prevent any memory allocations.
+ mp_sched_lock();
gc_lock();
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
@@ -77,6 +79,7 @@ void mp_irq_handler(mp_irq_obj_t *self) {
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
gc_unlock();
+ mp_sched_unlock();
} else {
// Schedule call to user function
mp_sched_schedule(self->handler, self->parent);