mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
py/scheduler: Add support for scheduling static C-based callbacks.
If MICROPY_SCHEDULER_STATIC_NODES is enabled then C code can declare a static mp_sched_node_t and schedule a callback using mp_sched_schedule_node(). In contrast to using mp_sched_schedule(), the node version will have at most one pending callback outstanding, and will always be able to schedule if there is nothing already scheduled on this node. This guarantees that the the callback will be called exactly once after it is scheduled. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
10
py/runtime.c
10
py/runtime.c
@@ -65,7 +65,15 @@ void mp_init(void) {
|
||||
// no pending exceptions to start with
|
||||
MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL;
|
||||
#if MICROPY_ENABLE_SCHEDULER
|
||||
MP_STATE_VM(sched_state) = MP_SCHED_IDLE;
|
||||
#if MICROPY_SCHEDULER_STATIC_NODES
|
||||
if (MP_STATE_VM(sched_head) == NULL) {
|
||||
// no pending callbacks to start with
|
||||
MP_STATE_VM(sched_state) = MP_SCHED_IDLE;
|
||||
} else {
|
||||
// pending callbacks are on the list, eg from before a soft reset
|
||||
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
|
||||
}
|
||||
#endif
|
||||
MP_STATE_VM(sched_idx) = 0;
|
||||
MP_STATE_VM(sched_len) = 0;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user