Skip to main content

embassy_executor/
pender.rs

1//! The pender: the callback executors use to notify they have work to do.
2
3unitrait::unitrait! {
4    /// The pender: the callback executors use to notify they have work to do.
5    ///
6    /// There is one global pender for the whole program, registered with the
7    /// [`pender_impl!`](crate::pender_impl) macro. It is provided by the
8    /// platform/architecture implementation, either the built-in ones enabled by the
9    /// `platform-*` Cargo features, or a custom one.
10    pub trait Pender {
11        /// Called when an executor has work to do.
12        ///
13        /// The implementation must arrange for [`crate::raw::Executor::poll`] to be called on the
14        /// executor identified by `context` as soon as possible.
15        ///
16        /// `context` is the arbitrary data passed to [`crate::raw::Executor::new`] by whoever
17        /// created the executor. It can be used to differentiate between executors, or to pass a
18        /// pointer to a callback that should be called.
19        ///
20        /// This function can be called from *any* context: any thread, any interrupt priority
21        /// level, etc. It may be called synchronously from any executor method call as well.
22        /// The implementation must deal with this correctly.
23        ///
24        /// In particular, the implementation must NOT call `poll` directly from within this
25        /// function, as this violates the requirement for `poll` to not be called reentrantly.
26        #[symbol = "__pender"]
27        fn pend(context: *mut ());
28    }
29
30    /// The global [`Pender`] implementation.
31    pub(crate) struct PenderImpl;
32
33    /// Register a type as the global [`Pender`] implementation.
34    ///
35    /// This must be done exactly once in the crate tree, by the platform/architecture
36    /// implementation. Enabling a `platform-*` Cargo feature on `embassy-executor` registers
37    /// the corresponding built-in pender.
38    macro pender_impl(path = $crate::pender);
39}