From 1ab8176e1dcfb8eccead10927b65f914a237bfa2 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 27 May 2025 17:04:03 +0200 Subject: [PATCH] mpconfig: Use RUN_BACKGROUND_TASKS as the micropython event hook This is a newer abstraction in micropython; it'll for instance allow background tasks to be checked once per ms in the internal select module modselect. Because `MICROPY_INTERNAL_EVENT_HOOK` is used in a few locations, our own CIRCUITPY-CHANGE call to `RUN_BACKGROUND_TASKS` can be nixed. Specifically, `mp_event_handle_nowait` calls `MICROPY_INTERNAL_EVENT_HOOK` so paths from it don't need `RUN_BACKGROUND_TASKS` anymore. --- py/circuitpy_mpconfig.h | 1 + py/scheduler.c | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index d6658867b7d1d..73d6d682e8c5b 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -452,6 +452,7 @@ void background_callback_run_all(void); #define MICROPY_VM_HOOK_LOOP RUN_BACKGROUND_TASKS; #define MICROPY_VM_HOOK_RETURN RUN_BACKGROUND_TASKS; +#define MICROPY_INTERNAL_EVENT_HOOK (RUN_BACKGROUND_TASKS) // CIRCUITPY_AUTORELOAD_DELAY_MS = 0 will completely disable autoreload. #ifndef CIRCUITPY_AUTORELOAD_DELAY_MS diff --git a/py/scheduler.c b/py/scheduler.c index 91ef7e63b38f1..99952d28aca61 100644 --- a/py/scheduler.c +++ b/py/scheduler.c @@ -271,10 +271,6 @@ void mp_event_wait_indefinite(void) { MICROPY_EVENT_POLL_HOOK #else mp_event_handle_nowait(); - - // CIRCUITPY-CHANGE: don't starve CircuitPython background tasks - RUN_BACKGROUND_TASKS; - MICROPY_INTERNAL_WFE(-1); #endif } @@ -287,10 +283,6 @@ void mp_event_wait_ms(mp_uint_t timeout_ms) { MICROPY_EVENT_POLL_HOOK #else mp_event_handle_nowait(); - - // CIRCUITPY-CHANGE: don't starve CircuitPython background tasks - RUN_BACKGROUND_TASKS; - MICROPY_INTERNAL_WFE(timeout_ms); #endif }