aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2023-08-14 15:16:40 +0200
committerDániel Buga <[email protected]>2023-08-14 15:16:40 +0200
commit4c4b12c307bf77516299eb73f9da00ef777b9814 (patch)
treed10f1c9dc44d60ead7245c988220da268cdd7746 /embassy-executor
parentf6007869bffd3ed4f48e74222dc40d11c7c87ec0 (diff)
Make PenderContext opaque
Diffstat (limited to 'embassy-executor')
-rw-r--r--embassy-executor/src/arch/cortex_m.rs6
-rw-r--r--embassy-executor/src/arch/riscv32.rs2
-rw-r--r--embassy-executor/src/arch/std.rs2
-rw-r--r--embassy-executor/src/arch/wasm.rs2
-rw-r--r--embassy-executor/src/arch/xtensa.rs2
-rw-r--r--embassy-executor/src/raw/mod.rs23
6 files changed, 29 insertions, 8 deletions
diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs
index 7f8a97ef1..439db0fc0 100644
--- a/embassy-executor/src/arch/cortex_m.rs
+++ b/embassy-executor/src/arch/cortex_m.rs
@@ -36,6 +36,7 @@ unsafe fn nvic_pend(irq: u16) {
36#[export_name = "__pender"] 36#[export_name = "__pender"]
37fn __pender(context: PenderContext) { 37fn __pender(context: PenderContext) {
38 unsafe { 38 unsafe {
39 let context: usize = core::mem::transmute(context);
39 // Safety: `context` is either `usize::MAX` created by `Executor::run`, or a valid interrupt 40 // Safety: `context` is either `usize::MAX` created by `Executor::run`, or a valid interrupt
40 // request number given to `InterruptExecutor::start`. 41 // request number given to `InterruptExecutor::start`.
41 if context as usize == usize::MAX { 42 if context as usize == usize::MAX {
@@ -56,6 +57,7 @@ fn __pender(_context: PenderContext) {
56#[export_name = "__pender"] 57#[export_name = "__pender"]
57fn __pender(context: PenderContext) { 58fn __pender(context: PenderContext) {
58 unsafe { 59 unsafe {
60 let context: usize = core::mem::transmute(context);
59 // Safety: `context` is the same value we passed to `InterruptExecutor::start`, which must 61 // Safety: `context` is the same value we passed to `InterruptExecutor::start`, which must
60 // be a valid interrupt request number. 62 // be a valid interrupt request number.
61 nvic_pend(context as u16) 63 nvic_pend(context as u16)
@@ -78,7 +80,7 @@ mod thread {
78 80
79 impl ThreadContext for Context { 81 impl ThreadContext for Context {
80 fn context(&self) -> PenderContext { 82 fn context(&self) -> PenderContext {
81 usize::MAX 83 unsafe { core::mem::transmute(usize::MAX) }
82 } 84 }
83 85
84 fn wait(&mut self) { 86 fn wait(&mut self) {
@@ -106,7 +108,7 @@ mod interrupt {
106 T: InterruptNumber, 108 T: InterruptNumber,
107 { 109 {
108 fn context(&self) -> PenderContext { 110 fn context(&self) -> PenderContext {
109 self.number() as usize 111 unsafe { core::mem::transmute(self.number() as usize) }
110 } 112 }
111 113
112 fn enable(&self) { 114 fn enable(&self) {
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index 886056e84..f76a4bcf6 100644
--- a/embassy-executor/src/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
@@ -28,7 +28,7 @@ mod thread {
28 28
29 impl ThreadContext for Context { 29 impl ThreadContext for Context {
30 fn context(&self) -> PenderContext { 30 fn context(&self) -> PenderContext {
31 0 31 unsafe { core::mem::transmute(0) }
32 } 32 }
33 33
34 fn wait(&mut self) { 34 fn wait(&mut self) {
diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs
index d2a069d1c..d55de118d 100644
--- a/embassy-executor/src/arch/std.rs
+++ b/embassy-executor/src/arch/std.rs
@@ -29,7 +29,7 @@ mod thread {
29 29
30 impl ThreadContext for Context { 30 impl ThreadContext for Context {
31 fn context(&self) -> PenderContext { 31 fn context(&self) -> PenderContext {
32 self.signaler as *const _ as usize 32 unsafe { core::mem::transmute(self.signaler) }
33 } 33 }
34 34
35 fn wait(&mut self) { 35 fn wait(&mut self) {
diff --git a/embassy-executor/src/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs
index 634f48d1a..452c3e394 100644
--- a/embassy-executor/src/arch/wasm.rs
+++ b/embassy-executor/src/arch/wasm.rs
@@ -49,7 +49,7 @@ mod thread {
49 pub fn new() -> Self { 49 pub fn new() -> Self {
50 let ctx = &*Box::leak(Box::new(WasmContext::new())); 50 let ctx = &*Box::leak(Box::new(WasmContext::new()));
51 Self { 51 Self {
52 inner: raw::Executor::new(ctx as *const _ as usize), 52 inner: raw::Executor::new(unsafe { core::mem::transmute(ctx) }),
53 ctx, 53 ctx,
54 not_send: PhantomData, 54 not_send: PhantomData,
55 } 55 }
diff --git a/embassy-executor/src/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs
index 3986c6c19..1aea9f230 100644
--- a/embassy-executor/src/arch/xtensa.rs
+++ b/embassy-executor/src/arch/xtensa.rs
@@ -26,7 +26,7 @@ mod thread {
26 26
27 impl ThreadContext for Context { 27 impl ThreadContext for Context {
28 fn context(&self) -> PenderContext { 28 fn context(&self) -> PenderContext {
29 0 29 unsafe { core::mem::transmute(0) }
30 } 30 }
31 31
32 fn wait(&mut self) { 32 fn wait(&mut self) {
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index a0a940e25..4a6e45535 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -292,10 +292,29 @@ impl<F: Future + 'static, const N: usize> TaskPool<F, N> {
292} 292}
293 293
294/// Context given to the thread-mode executor's pender. 294/// Context given to the thread-mode executor's pender.
295pub type PenderContext = usize; 295#[repr(transparent)]
296#[derive(Clone, Copy)]
297pub struct PenderContext(usize);
296 298
299/// Platform/architecture-specific action executed when an executor has pending work.
300///
301/// When a task within an executor is woken, the `Pender` is called. This does a
302/// platform/architecture-specific action to signal there is pending work in the executor.
303/// When this happens, you must arrange for [`Executor::poll`] to be called.
304///
305/// You can think of it as a waker, but for the whole executor.
306///
307/// Platform/architecture implementations must provide a function that can be referred to as:
308///
309/// ```rust
310/// use embassy_executor::raw::PenderContext;
311///
312/// extern "Rust" {
313/// fn __pender(context: PenderContext);
314/// }
315/// ```
297#[derive(Clone, Copy)] 316#[derive(Clone, Copy)]
298pub(crate) struct Pender(PenderContext); 317pub struct Pender(PenderContext);
299 318
300unsafe impl Send for Pender {} 319unsafe impl Send for Pender {}
301unsafe impl Sync for Pender {} 320unsafe impl Sync for Pender {}