diff options
author | iabdalkader <i.abdalkader@gmail.com> | 2025-09-25 16:28:38 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-10-03 00:52:29 +1000 |
commit | c57aebf790c40125b663231ec4307d2a3f3cf193 (patch) | |
tree | 77224fb0830b2d5ecd2c5dca90d6cb3986ad202e /py/runtime.h | |
parent | c91e091ad72e3e15ca8981bd953f64714a5afb3e (diff) |
py/scheduler: Allow selective handling in mp_handle_pending.
Extend mp_handle_pending to support three distinct behaviors via
mp_handle_pending_internal():
- MP_HANDLE_PENDING_CALLBACKS_ONLY: process callbacks only
- MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS: callbacks + raise exceptions
- MP_HANDLE_PENDING_CALLBACKS_AND_CLEAR_EXCEPTIONS: callbacks + clear only
Original mp_handle_pending(bool) preserved as inline wrapper for
backward compatibility.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Diffstat (limited to 'py/runtime.h')
-rw-r--r-- | py/runtime.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/py/runtime.h b/py/runtime.h index f42039cab..0ef811c1e 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -52,6 +52,12 @@ typedef enum { MP_ARG_KW_ONLY = 0x200, } mp_arg_flag_t; +typedef enum { + MP_HANDLE_PENDING_CALLBACKS_ONLY, + MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS, + MP_HANDLE_PENDING_CALLBACKS_AND_CLEAR_EXCEPTIONS, +} mp_handle_pending_behaviour_t; + typedef union _mp_arg_val_t { bool u_bool; mp_int_t u_int; @@ -100,7 +106,14 @@ void mp_sched_keyboard_interrupt(void); #if MICROPY_ENABLE_VM_ABORT void mp_sched_vm_abort(void); #endif -void mp_handle_pending(bool raise_exc); + +void mp_handle_pending_internal(mp_handle_pending_behaviour_t behavior); + +static inline void mp_handle_pending(bool raise_exc) { + mp_handle_pending_internal(raise_exc ? + MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS : + MP_HANDLE_PENDING_CALLBACKS_AND_CLEAR_EXCEPTIONS); +} #if MICROPY_ENABLE_SCHEDULER void mp_sched_lock(void); |