Remove Pender wrapper

This commit is contained in:
Dániel Buga 2023-08-12 22:05:19 +02:00
parent 675b7fb605
commit fbf50cdae8
4 changed files with 29 additions and 31 deletions

View File

@ -17,7 +17,7 @@ mod thread {
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use crate::raw::util::UninitCell; use crate::raw::util::UninitCell;
use crate::raw::{OpaqueThreadContext, Pender, PenderInner}; use crate::raw::{OpaqueThreadContext, Pender};
use crate::{raw, Spawner}; use crate::{raw, Spawner};
#[export_name = "__thread_mode_pender"] #[export_name = "__thread_mode_pender"]
@ -52,9 +52,7 @@ mod thread {
pub fn new() -> Self { pub fn new() -> Self {
let ctx = &*Box::leak(Box::new(WasmContext::new())); let ctx = &*Box::leak(Box::new(WasmContext::new()));
Self { Self {
inner: raw::Executor::new(Pender(PenderInner::Thread(OpaqueThreadContext( inner: raw::Executor::new(Pender::Thread(OpaqueThreadContext(ctx as *const _ as usize))),
ctx as *const _ as usize,
)))),
ctx, ctx,
not_send: PhantomData, not_send: PhantomData,
} }

View File

@ -5,7 +5,7 @@ use core::mem::MaybeUninit;
use atomic_polyfill::{AtomicBool, Ordering}; 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`]. /// An interrupt source that can be used to drive an [`InterruptExecutor`].
// Name pending // Name pending
@ -100,7 +100,7 @@ impl InterruptModeExecutor {
unsafe { unsafe {
(&mut *self.executor.get()) (&mut *self.executor.get())
.as_mut_ptr() .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() }; let executor = unsafe { (&*self.executor.get()).assume_init_ref() };

View File

@ -308,19 +308,6 @@ pub struct OpaqueThreadContext(pub(crate) usize);
#[repr(transparent)] #[repr(transparent)]
pub struct OpaqueInterruptContext(pub(crate) usize); 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. /// 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 /// 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. /// 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. /// 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 { impl Pender {
/// Create a `Pender` that will call an arbitrary function pointer. /// 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. /// - `context`: Opaque context pointer, that will be passed to the function pointer.
#[cfg(feature = "pender-callback")] #[cfg(feature = "pender-callback")]
pub fn new_from_callback(func: fn(*mut ()), context: *mut ()) -> Self { pub fn new_from_callback(func: fn(*mut ()), context: *mut ()) -> Self {
Self(PenderInner::Callback { Self::Callback { func, context }
func,
context: context.into(),
})
} }
} }
impl Pender { impl Pender {
pub(crate) fn pend(&self) { pub(crate) fn pend(self) {
match self.0 { match self {
#[cfg(feature = "executor-thread")] #[cfg(feature = "executor-thread")]
PenderInner::Thread(core_id) => { Pender::Thread(core_id) => {
extern "Rust" { extern "Rust" {
fn __thread_mode_pender(core_id: OpaqueThreadContext); fn __thread_mode_pender(core_id: OpaqueThreadContext);
} }
unsafe { __thread_mode_pender(core_id) }; unsafe { __thread_mode_pender(core_id) };
} }
#[cfg(feature = "executor-interrupt")] #[cfg(feature = "executor-interrupt")]
PenderInner::Interrupt(interrupt) => { Pender::Interrupt(interrupt) => {
extern "Rust" { extern "Rust" {
fn __interrupt_mode_pender(interrupt: OpaqueInterruptContext); fn __interrupt_mode_pender(interrupt: OpaqueInterruptContext);
} }
unsafe { __interrupt_mode_pender(interrupt) }; unsafe { __interrupt_mode_pender(interrupt) };
} }
#[cfg(feature = "pender-callback")] #[cfg(feature = "pender-callback")]
PenderInner::Callback { func, context } => func(context), Pender::Callback { func, context } => func(context),
} }
} }
} }

View File

@ -2,7 +2,7 @@
use core::marker::PhantomData; use core::marker::PhantomData;
use crate::raw::{OpaqueThreadContext, Pender, PenderInner}; use crate::raw::{OpaqueThreadContext, Pender};
use crate::{raw, Spawner}; use crate::{raw, Spawner};
/// TODO /// TODO
@ -43,7 +43,7 @@ impl<C: ThreadContext> ThreadModeExecutor<C> {
/// Create a new Executor. /// Create a new Executor.
pub fn with_context(context: C) -> Self { pub fn with_context(context: C) -> Self {
Self { Self {
inner: raw::Executor::new(Pender(PenderInner::Thread(context.context()))), inner: raw::Executor::new(Pender::Thread(context.context())),
context, context,
not_send: PhantomData, not_send: PhantomData,
} }