summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-02-06 01:05:47 +1100
committerDamien George <damien.p.george@gmail.com>2020-02-07 16:08:20 +1100
commit98a3911c430b0cc96e1821d7ca589b9be3355fc3 (patch)
tree1182ab05b8366c85f40700548bd003d2a6bd3597 /py
parent7a5752a7489f6be1c7307455b33119888392a09d (diff)
downloadmicropython-98a3911c430b0cc96e1821d7ca589b9be3355fc3.tar.gz
micropython-98a3911c430b0cc96e1821d7ca589b9be3355fc3.zip
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.
Diffstat (limited to 'py')
-rw-r--r--py/runtime.h2
-rw-r--r--py/scheduler.c14
2 files changed, 10 insertions, 6 deletions
diff --git a/py/runtime.h b/py/runtime.h
index b54b17b683..1c078ae81a 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -64,7 +64,7 @@ extern const byte mp_binary_op_method_name[];
void mp_init(void);
void mp_deinit(void);
-void mp_handle_pending(void);
+void mp_handle_pending(bool raise_exc);
void mp_handle_pending_tail(mp_uint_t atomic_state);
#if MICROPY_ENABLE_SCHEDULER
diff --git a/py/scheduler.c b/py/scheduler.c
index e7cbb524de..ff88be9583 100644
--- a/py/scheduler.c
+++ b/py/scheduler.c
@@ -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);
+ }
}
}