summaryrefslogtreecommitdiff
path: root/py/scheduler.c
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2021-05-10 21:53:22 -0500
committerDamien George <damien@micropython.org>2021-06-19 09:43:44 +1000
commitca920f72184c50f61002aa9d5cd01555b1e28b7b (patch)
treea46b6cb9c91a275015b351443d1cb1181d8c5d14 /py/scheduler.c
parent7c51cb2307eaca1a1ccc071e0bb5eb4a5f734610 (diff)
py/mpstate: Make exceptions thread-local.
This moves mp_pending_exception from mp_state_vm_t to mp_state_thread_t. This allows exceptions to be scheduled on a specific thread. Signed-off-by: David Lechner <david@pybricks.com>
Diffstat (limited to 'py/scheduler.c')
-rw-r--r--py/scheduler.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/py/scheduler.c b/py/scheduler.c
index 0671a34a8..0114a7a58 100644
--- a/py/scheduler.c
+++ b/py/scheduler.c
@@ -29,7 +29,7 @@
#include "py/runtime.h"
void MICROPY_WRAP_MP_SCHED_EXCEPTION(mp_sched_exception)(mp_obj_t exc) {
- MP_STATE_VM(mp_pending_exception) = exc;
+ MP_STATE_THREAD(mp_pending_exception) = exc;
#if MICROPY_ENABLE_SCHEDULER
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
@@ -66,9 +66,9 @@ void mp_handle_pending(bool raise_exc) {
mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
// Re-check state is still pending now that we're in the atomic section.
if (MP_STATE_VM(sched_state) == MP_SCHED_PENDING) {
- mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
+ mp_obj_t obj = MP_STATE_THREAD(mp_pending_exception);
if (obj != MP_OBJ_NULL) {
- MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
+ MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL;
if (!mp_sched_num_pending()) {
MP_STATE_VM(sched_state) = MP_SCHED_IDLE;
}
@@ -115,7 +115,7 @@ void mp_sched_unlock(void) {
assert(MP_STATE_VM(sched_state) < 0);
if (++MP_STATE_VM(sched_state) == 0) {
// vm became unlocked
- if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL || mp_sched_num_pending()) {
+ if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL || mp_sched_num_pending()) {
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
} else {
MP_STATE_VM(sched_state) = MP_SCHED_IDLE;
@@ -148,9 +148,9 @@ bool MICROPY_WRAP_MP_SCHED_SCHEDULE(mp_sched_schedule)(mp_obj_t function, mp_obj
// A variant of this is inlined in the VM at the pending exception check
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;
+ if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL) {
+ mp_obj_t obj = MP_STATE_THREAD(mp_pending_exception);
+ MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL;
if (raise_exc) {
nlr_raise(obj);
}