py/scheduler: Add "raise_exc" argument to mp_handle_pending.

Previous behaviour is when this argument is set to "true", in which case
the function will raise any pending exception.  Setting it to "false" will
cancel any pending exception.
This commit is contained in:
Damien George
2020-02-06 01:05:47 +11:00
parent 7a5752a748
commit 98a3911c43
11 changed files with 30 additions and 26 deletions

View File

@@ -44,7 +44,7 @@ static inline bool mp_sched_empty(void) {
}
// A variant of this is inlined in the VM at the pending exception check
void mp_handle_pending(void) {
void mp_handle_pending(bool raise_exc) {
if (MP_STATE_VM(sched_state) == MP_SCHED_PENDING) {
mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
@@ -53,8 +53,10 @@ void mp_handle_pending(void) {
if (!mp_sched_num_pending()) {
MP_STATE_VM(sched_state) = MP_SCHED_IDLE;
}
MICROPY_END_ATOMIC_SECTION(atomic_state);
nlr_raise(obj);
if (raise_exc) {
MICROPY_END_ATOMIC_SECTION(atomic_state);
nlr_raise(obj);
}
}
mp_handle_pending_tail(atomic_state);
}
@@ -121,11 +123,13 @@ bool mp_sched_schedule(mp_obj_t function, mp_obj_t arg) {
#else // MICROPY_ENABLE_SCHEDULER
// A variant of this is inlined in the VM at the pending exception check
void mp_handle_pending(void) {
void mp_handle_pending(bool raise_exc) {
if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) {
mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
nlr_raise(obj);
if (raise_exc) {
nlr_raise(obj);
}
}
}