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/runtime.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/runtime.h')
| -rw-r--r-- | py/runtime.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/py/runtime.h b/py/runtime.h index f0d41f38d..4393fbfa8 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -57,6 +57,15 @@ typedef struct _mp_arg_t { mp_arg_val_t defval; } mp_arg_t; +struct _mp_sched_node_t; + +typedef void (*mp_sched_callback_t)(struct _mp_sched_node_t *); + +typedef struct _mp_sched_node_t { + mp_sched_callback_t callback; + struct _mp_sched_node_t *next; +} mp_sched_node_t; + // Tables mapping operator enums to qstrs, defined in objtype.c extern const byte mp_unary_op_method_name[]; extern const byte mp_binary_op_method_name[]; @@ -74,6 +83,7 @@ void mp_sched_lock(void); void mp_sched_unlock(void); #define mp_sched_num_pending() (MP_STATE_VM(sched_len)) bool mp_sched_schedule(mp_obj_t function, mp_obj_t arg); +bool mp_sched_schedule_node(mp_sched_node_t *node, mp_sched_callback_t callback); #endif // extra printing method specifically for mp_obj_t's which are integral type |
