embassy-executor

Crates

git

Versions

riscv32

Flavors

embassy_executor::raw

Struct 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 pender function, as shown below. The executor will call it to notify you it has work to do. You must arrange for poll() to be called as soon as possible.
  • Enabling arch-xx features will define a pender function for you. This means that you are limited to using the executors provided to you by the architecture/platform implementation. If you need a different executor, you must not enable arch-xx features.

The pender 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 the pender callback, as this violates the requirement for poll to not be called reentrantly.

The pender function must be exported with the name __pender and have the following signature:

#[export_name = "__pender"]
fn pender(context: *mut ()) {
   // schedule `poll()` to be called
}

The context argument is a piece of arbitrary data the executor will pass to the pender. You can set the context when calling Executor::new(). You can use it to, for example, differentiate between executors, or to pass a pointer to a callback that should be called.

Implementations§

Source§

impl Executor

Source

pub fn new(context: *mut ()) -> Self

Create a new executor.

When the executor has work to do, it will call the pender function and pass context to it.

See Executor docs for details on the pender.

Source

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 the pender. It is OK to call poll even when not requested by the pender, but it wastes energy.

§Safety

You must NOT call poll reentrantly on the same executor.

In particular, note that poll may call the pender synchronously. Therefore, you must NOT directly call poll() from the pender callback. Instead, the callback has to somehow schedule for poll() to be called later, at a time you know for sure there’s no poll() already running.

Source

pub fn spawner(&'static self) -> Spawner

Get a spawner that spawns tasks in this executor.

It is OK to call this method multiple times to obtain multiple Spawners. You may also copy Spawners.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.