aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2023-08-12 22:05:19 +0200
committerDániel Buga <[email protected]>2023-08-12 22:13:08 +0200
commitfbf50cdae899dc1cd2f232b880e096d0fc51f49c (patch)
tree0dfbff67b15a44581f135d121ee48d362d9cb6ed /embassy-executor/src
parent675b7fb6056d8c3dfaca759b7cd373e2f4a0e111 (diff)
Remove Pender wrapper
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/arch/wasm.rs6
-rw-r--r--embassy-executor/src/interrupt.rs4
-rw-r--r--embassy-executor/src/raw/mod.rs42
-rw-r--r--embassy-executor/src/thread.rs4
4 files changed, 27 insertions, 29 deletions
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 {
17 use wasm_bindgen::prelude::*; 17 use wasm_bindgen::prelude::*;
18 18
19 use crate::raw::util::UninitCell; 19 use crate::raw::util::UninitCell;
20 use crate::raw::{OpaqueThreadContext, Pender, PenderInner}; 20 use crate::raw::{OpaqueThreadContext, Pender};
21 use crate::{raw, Spawner}; 21 use crate::{raw, Spawner};
22 22
23 #[export_name = "__thread_mode_pender"] 23 #[export_name = "__thread_mode_pender"]
@@ -52,9 +52,7 @@ mod thread {
52 pub fn new() -> Self { 52 pub fn new() -> Self {
53 let ctx = &*Box::leak(Box::new(WasmContext::new())); 53 let ctx = &*Box::leak(Box::new(WasmContext::new()));
54 Self { 54 Self {
55 inner: raw::Executor::new(Pender(PenderInner::Thread(OpaqueThreadContext( 55 inner: raw::Executor::new(Pender::Thread(OpaqueThreadContext(ctx as *const _ as usize))),
56 ctx as *const _ as usize,
57 )))),
58 ctx, 56 ctx,
59 not_send: PhantomData, 57 not_send: PhantomData,
60 } 58 }
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;
5 5
6use atomic_polyfill::{AtomicBool, Ordering}; 6use atomic_polyfill::{AtomicBool, Ordering};
7 7
8use crate::raw::{self, OpaqueInterruptContext, Pender, PenderInner}; 8use crate::raw::{self, OpaqueInterruptContext, Pender};
9 9
10/// An interrupt source that can be used to drive an [`InterruptExecutor`]. 10/// An interrupt source that can be used to drive an [`InterruptExecutor`].
11// Name pending 11// Name pending
@@ -100,7 +100,7 @@ impl InterruptModeExecutor {
100 unsafe { 100 unsafe {
101 (&mut *self.executor.get()) 101 (&mut *self.executor.get())
102 .as_mut_ptr() 102 .as_mut_ptr()
103 .write(raw::Executor::new(Pender(PenderInner::Interrupt(irq.context())))) 103 .write(raw::Executor::new(Pender::Interrupt(irq.context())))
104 } 104 }
105 105
106 let executor = unsafe { (&*self.executor.get()).assume_init_ref() }; 106 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,27 +308,30 @@ pub struct OpaqueThreadContext(pub(crate) usize);
308#[repr(transparent)] 308#[repr(transparent)]
309pub struct OpaqueInterruptContext(pub(crate) usize); 309pub struct OpaqueInterruptContext(pub(crate) usize);
310 310
311/// Platform/architecture-specific action executed when an executor has pending work.
312///
313/// When a task within an executor is woken, the `Pender` is called. This does a
314/// platform/architecture-specific action to signal there is pending work in the executor.
315/// When this happens, you must arrange for [`Executor::poll`] to be called.
316///
317/// You can think of it as a waker, but for the whole executor.
311#[derive(Clone, Copy)] 318#[derive(Clone, Copy)]
312pub(crate) enum PenderInner { 319pub enum Pender {
320 /// Pender for a thread-mode executor.
313 #[cfg(feature = "executor-thread")] 321 #[cfg(feature = "executor-thread")]
314 Thread(OpaqueThreadContext), 322 Thread(OpaqueThreadContext),
323
324 /// Pender for an interrupt-mode executor.
315 #[cfg(feature = "executor-interrupt")] 325 #[cfg(feature = "executor-interrupt")]
316 Interrupt(OpaqueInterruptContext), 326 Interrupt(OpaqueInterruptContext),
327
328 /// Arbitrary, dynamically dispatched pender.
317 #[cfg(feature = "pender-callback")] 329 #[cfg(feature = "pender-callback")]
318 Callback { func: fn(*mut ()), context: *mut () }, 330 Callback { func: fn(*mut ()), context: *mut () },
319} 331}
320 332
321unsafe impl Send for PenderInner {} 333unsafe impl Send for Pender {}
322unsafe impl Sync for PenderInner {} 334unsafe impl Sync for Pender {}
323
324/// Platform/architecture-specific action executed when an executor has pending work.
325///
326/// When a task within an executor is woken, the `Pender` is called. This does a
327/// platform/architecture-specific action to signal there is pending work in the executor.
328/// When this happens, you must arrange for [`Executor::poll`] to be called.
329///
330/// You can think of it as a waker, but for the whole executor.
331pub struct Pender(pub(crate) PenderInner);
332 335
333impl Pender { 336impl Pender {
334 /// Create a `Pender` that will call an arbitrary function pointer. 337 /// Create a `Pender` that will call an arbitrary function pointer.
@@ -339,32 +342,29 @@ impl Pender {
339 /// - `context`: Opaque context pointer, that will be passed to the function pointer. 342 /// - `context`: Opaque context pointer, that will be passed to the function pointer.
340 #[cfg(feature = "pender-callback")] 343 #[cfg(feature = "pender-callback")]
341 pub fn new_from_callback(func: fn(*mut ()), context: *mut ()) -> Self { 344 pub fn new_from_callback(func: fn(*mut ()), context: *mut ()) -> Self {
342 Self(PenderInner::Callback { 345 Self::Callback { func, context }
343 func,
344 context: context.into(),
345 })
346 } 346 }
347} 347}
348 348
349impl Pender { 349impl Pender {
350 pub(crate) fn pend(&self) { 350 pub(crate) fn pend(self) {
351 match self.0 { 351 match self {
352 #[cfg(feature = "executor-thread")] 352 #[cfg(feature = "executor-thread")]
353 PenderInner::Thread(core_id) => { 353 Pender::Thread(core_id) => {
354 extern "Rust" { 354 extern "Rust" {
355 fn __thread_mode_pender(core_id: OpaqueThreadContext); 355 fn __thread_mode_pender(core_id: OpaqueThreadContext);
356 } 356 }
357 unsafe { __thread_mode_pender(core_id) }; 357 unsafe { __thread_mode_pender(core_id) };
358 } 358 }
359 #[cfg(feature = "executor-interrupt")] 359 #[cfg(feature = "executor-interrupt")]
360 PenderInner::Interrupt(interrupt) => { 360 Pender::Interrupt(interrupt) => {
361 extern "Rust" { 361 extern "Rust" {
362 fn __interrupt_mode_pender(interrupt: OpaqueInterruptContext); 362 fn __interrupt_mode_pender(interrupt: OpaqueInterruptContext);
363 } 363 }
364 unsafe { __interrupt_mode_pender(interrupt) }; 364 unsafe { __interrupt_mode_pender(interrupt) };
365 } 365 }
366 #[cfg(feature = "pender-callback")] 366 #[cfg(feature = "pender-callback")]
367 PenderInner::Callback { func, context } => func(context), 367 Pender::Callback { func, context } => func(context),
368 } 368 }
369 } 369 }
370} 370}
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 @@
2 2
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4 4
5use crate::raw::{OpaqueThreadContext, Pender, PenderInner}; 5use crate::raw::{OpaqueThreadContext, Pender};
6use crate::{raw, Spawner}; 6use crate::{raw, Spawner};
7 7
8/// TODO 8/// TODO
@@ -43,7 +43,7 @@ impl<C: ThreadContext> ThreadModeExecutor<C> {
43 /// Create a new Executor. 43 /// Create a new Executor.
44 pub fn with_context(context: C) -> Self { 44 pub fn with_context(context: C) -> Self {
45 Self { 45 Self {
46 inner: raw::Executor::new(Pender(PenderInner::Thread(context.context()))), 46 inner: raw::Executor::new(Pender::Thread(context.context())),
47 context, 47 context,
48 not_send: PhantomData, 48 not_send: PhantomData,
49 } 49 }