diff options
author | Damien George <damien.p.george@gmail.com> | 2017-02-16 18:05:06 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-03-20 15:20:26 +1100 |
commit | 6e74d24f30bca3fb70876b1fb9a6b3a59850b83c (patch) | |
tree | 391a713749edac08db0efc45e6ff987b2f437dc0 /py/vm.c | |
parent | bf29fe2e138a30688cfb94ad3859f903f935ced1 (diff) |
py: Add micropython.schedule() function and associated runtime code.
Diffstat (limited to 'py/vm.c')
-rw-r--r-- | py/vm.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -1267,12 +1267,32 @@ yield: pending_exception_check: MICROPY_VM_HOOK_LOOP + + #if MICROPY_ENABLE_SCHEDULER + // This is an inlined variant of mp_handle_pending + if (MP_STATE_VM(sched_state) == MP_SCHED_PENDING) { + MARK_EXC_IP_SELECTIVE(); + mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); + mp_obj_t obj = MP_STATE_VM(mp_pending_exception); + if (obj != MP_OBJ_NULL) { + MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; + if (!mp_sched_num_pending()) { + MP_STATE_VM(sched_state) = MP_SCHED_IDLE; + } + MICROPY_END_ATOMIC_SECTION(atomic_state); + RAISE(obj); + } + mp_handle_pending_tail(atomic_state); + } + #else + // This is an inlined variant of mp_handle_pending if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) { MARK_EXC_IP_SELECTIVE(); mp_obj_t obj = MP_STATE_VM(mp_pending_exception); MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; RAISE(obj); } + #endif #if MICROPY_PY_THREAD_GIL #if MICROPY_PY_THREAD_GIL_VM_DIVISOR |