diff --git a/embassy-executor/src/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs index 4f5ce9c90..e244c0b3f 100644 --- a/embassy-executor/src/arch/wasm.rs +++ b/embassy-executor/src/arch/wasm.rs @@ -17,7 +17,7 @@ mod thread { use wasm_bindgen::prelude::*; use crate::raw::util::UninitCell; - use crate::raw::{OpaqueThreadContext, Pender, PenderInner}; + use crate::raw::{OpaqueThreadContext, Pender}; use crate::{raw, Spawner}; #[export_name = "__thread_mode_pender"] @@ -52,9 +52,7 @@ mod thread { pub fn new() -> Self { let ctx = &*Box::leak(Box::new(WasmContext::new())); Self { - inner: raw::Executor::new(Pender(PenderInner::Thread(OpaqueThreadContext( - ctx as *const _ as usize, - )))), + inner: raw::Executor::new(Pender::Thread(OpaqueThreadContext(ctx as *const _ as usize))), ctx, not_send: PhantomData, } diff --git a/embassy-executor/src/interrupt.rs b/embassy-executor/src/interrupt.rs index f8b0809da..c1084ea7b 100644 --- a/embassy-executor/src/interrupt.rs +++ b/embassy-executor/src/interrupt.rs @@ -5,7 +5,7 @@ use core::mem::MaybeUninit; use atomic_polyfill::{AtomicBool, Ordering}; -use crate::raw::{self, OpaqueInterruptContext, Pender, PenderInner}; +use crate::raw::{self, OpaqueInterruptContext, Pender}; /// An interrupt source that can be used to drive an [`InterruptExecutor`]. // Name pending @@ -100,7 +100,7 @@ impl InterruptModeExecutor { unsafe { (&mut *self.executor.get()) .as_mut_ptr() - .write(raw::Executor::new(Pender(PenderInner::Interrupt(irq.context())))) + .write(raw::Executor::new(Pender::Interrupt(irq.context()))) } let executor = unsafe { (&*self.executor.get()).assume_init_ref() }; diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index b4d70b1e9..7fd29db40 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs @@ -308,19 +308,6 @@ pub struct OpaqueThreadContext(pub(crate) usize); #[repr(transparent)] pub struct OpaqueInterruptContext(pub(crate) usize); -#[derive(Clone, Copy)] -pub(crate) enum PenderInner { - #[cfg(feature = "executor-thread")] - Thread(OpaqueThreadContext), - #[cfg(feature = "executor-interrupt")] - Interrupt(OpaqueInterruptContext), - #[cfg(feature = "pender-callback")] - Callback { func: fn(*mut ()), context: *mut () }, -} - -unsafe impl Send for PenderInner {} -unsafe impl Sync for PenderInner {} - /// Platform/architecture-specific action executed when an executor has pending work. /// /// When a task within an executor is woken, the `Pender` is called. This does a @@ -328,7 +315,23 @@ unsafe impl Sync for PenderInner {} /// When this happens, you must arrange for [`Executor::poll`] to be called. /// /// You can think of it as a waker, but for the whole executor. -pub struct Pender(pub(crate) PenderInner); +#[derive(Clone, Copy)] +pub enum Pender { + /// Pender for a thread-mode executor. + #[cfg(feature = "executor-thread")] + Thread(OpaqueThreadContext), + + /// Pender for an interrupt-mode executor. + #[cfg(feature = "executor-interrupt")] + Interrupt(OpaqueInterruptContext), + + /// Arbitrary, dynamically dispatched pender. + #[cfg(feature = "pender-callback")] + Callback { func: fn(*mut ()), context: *mut () }, +} + +unsafe impl Send for Pender {} +unsafe impl Sync for Pender {} impl Pender { /// Create a `Pender` that will call an arbitrary function pointer. @@ -339,32 +342,29 @@ impl Pender { /// - `context`: Opaque context pointer, that will be passed to the function pointer. #[cfg(feature = "pender-callback")] pub fn new_from_callback(func: fn(*mut ()), context: *mut ()) -> Self { - Self(PenderInner::Callback { - func, - context: context.into(), - }) + Self::Callback { func, context } } } impl Pender { - pub(crate) fn pend(&self) { - match self.0 { + pub(crate) fn pend(self) { + match self { #[cfg(feature = "executor-thread")] - PenderInner::Thread(core_id) => { + Pender::Thread(core_id) => { extern "Rust" { fn __thread_mode_pender(core_id: OpaqueThreadContext); } unsafe { __thread_mode_pender(core_id) }; } #[cfg(feature = "executor-interrupt")] - PenderInner::Interrupt(interrupt) => { + Pender::Interrupt(interrupt) => { extern "Rust" { fn __interrupt_mode_pender(interrupt: OpaqueInterruptContext); } unsafe { __interrupt_mode_pender(interrupt) }; } #[cfg(feature = "pender-callback")] - PenderInner::Callback { func, context } => func(context), + Pender::Callback { func, context } => func(context), } } } diff --git a/embassy-executor/src/thread.rs b/embassy-executor/src/thread.rs index 9bbe29500..2d2c6daa5 100644 --- a/embassy-executor/src/thread.rs +++ b/embassy-executor/src/thread.rs @@ -2,7 +2,7 @@ use core::marker::PhantomData; -use crate::raw::{OpaqueThreadContext, Pender, PenderInner}; +use crate::raw::{OpaqueThreadContext, Pender}; use crate::{raw, Spawner}; /// TODO @@ -43,7 +43,7 @@ impl ThreadModeExecutor { /// Create a new Executor. pub fn with_context(context: C) -> Self { Self { - inner: raw::Executor::new(Pender(PenderInner::Thread(context.context()))), + inner: raw::Executor::new(Pender::Thread(context.context())), context, not_send: PhantomData, }