diff options
author | Damien George <damien@micropython.org> | 2022-03-23 17:13:03 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-04-14 12:31:53 +1000 |
commit | 75506e496f7545c43c4d76bac131c4e01c258fa5 (patch) | |
tree | cbd1c429156a780a559ece6f98e260f52a877f0b /py/mpstate.h | |
parent | d242a9b7f7b6d4e744889d5af6c17dfb54aed8c3 (diff) |
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>
Diffstat (limited to 'py/mpstate.h')
-rw-r--r-- | py/mpstate.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/py/mpstate.h b/py/mpstate.h index a493b780a..ab6090e1a 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -241,6 +241,16 @@ typedef struct _mp_state_vm_t { #if MICROPY_ENABLE_SCHEDULER volatile int16_t sched_state; + + #if MICROPY_SCHEDULER_STATIC_NODES + // These will usually point to statically allocated memory. They are not + // traced by the GC. They are assumed to be zero'd out before mp_init() is + // called (usually because this struct lives in the BSS). + struct _mp_sched_node_t *sched_head; + struct _mp_sched_node_t *sched_tail; + #endif + + // These index sched_queue. uint8_t sched_len; uint8_t sched_idx; #endif |