py/scheduler: Add optional port hook for when something is scheduled.

So that a port can "wake up" when there is work to do.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-04-25 22:24:49 +10:00
parent e9e9c76ddf
commit 916c3fd23f
2 changed files with 7 additions and 0 deletions

View File

@ -550,6 +550,12 @@
#define MICROPY_VM_HOOK_RETURN #define MICROPY_VM_HOOK_RETURN
#endif #endif
// Hook for mp_sched_schedule when a function gets scheduled on sched_queue
// (this macro executes within an atomic section)
#ifndef MICROPY_SCHED_HOOK_SCHEDULED
#define MICROPY_SCHED_HOOK_SCHEDULED
#endif
// Whether to include the garbage collector // Whether to include the garbage collector
#ifndef MICROPY_ENABLE_GC #ifndef MICROPY_ENABLE_GC
#define MICROPY_ENABLE_GC (0) #define MICROPY_ENABLE_GC (0)

View File

@ -134,6 +134,7 @@ bool MICROPY_WRAP_MP_SCHED_SCHEDULE(mp_sched_schedule)(mp_obj_t function, mp_obj
uint8_t iput = IDX_MASK(MP_STATE_VM(sched_idx) + MP_STATE_VM(sched_len)++); uint8_t iput = IDX_MASK(MP_STATE_VM(sched_idx) + MP_STATE_VM(sched_len)++);
MP_STATE_VM(sched_queue)[iput].func = function; MP_STATE_VM(sched_queue)[iput].func = function;
MP_STATE_VM(sched_queue)[iput].arg = arg; MP_STATE_VM(sched_queue)[iput].arg = arg;
MICROPY_SCHED_HOOK_SCHEDULED;
ret = true; ret = true;
} else { } else {
// schedule queue is full // schedule queue is full