Struct embassy_executor::raw::Executor
source · pub struct Executor { /* private fields */ }Expand description
Raw executor.
This is the core of the Embassy executor. It is low-level, requiring manual handling of wakeups and task polling. If you can, prefer using one of the higher level executors.
The raw executor leaves it up to you to handle wakeups and scheduling:
- To get the executor to do work, call
poll(). This will poll all queued tasks (all tasks that “want to run”). - You must supply a
signal_fn. The executor will call it to notify you it has work to do. You must arrange forpoll()to be called as soon as possible.
signal_fn can be called from any context: any thread, any interrupt priority
level, etc. It may be called synchronously from any Executor method call as well.
You must deal with this correctly.
In particular, you must NOT call poll directly from signal_fn, as this violates
the requirement for poll to not be called reentrantly.
Implementations
sourceimpl Executor
impl Executor
sourcepub fn new(signal_fn: fn(_: *mut ()), signal_ctx: *mut ()) -> Self
pub fn new(signal_fn: fn(_: *mut ()), signal_ctx: *mut ()) -> Self
Create a new executor.
When the executor has work to do, it will call signal_fn with
signal_ctx as argument.
See Executor docs for details on signal_fn.
sourcepub unsafe fn poll(&'static self)
pub unsafe fn poll(&'static self)
Poll all queued tasks in this executor.
This loops over all tasks that are queued to be polled (i.e. they’re freshly spawned or they’ve been woken). Other tasks are not polled.
You must call poll after receiving a call to signal_fn. It is OK
to call poll even when not requested by signal_fn, but it wastes
energy.
Safety
You must NOT call poll reentrantly on the same executor.
In particular, note that poll may call signal_fn synchronously. Therefore, you
must NOT directly call poll() from your signal_fn. Instead, signal_fn has to
somehow schedule for poll() to be called later, at a time you know for sure there’s
no poll() already running.