diff options
Diffstat (limited to 'embassy-executor/src/arch')
| -rw-r--r-- | embassy-executor/src/arch/avr.rs | 4 | ||||
| -rw-r--r-- | embassy-executor/src/arch/cortex_ar.rs | 11 | ||||
| -rw-r--r-- | embassy-executor/src/arch/cortex_m.rs | 4 | ||||
| -rw-r--r-- | embassy-executor/src/arch/riscv32.rs | 4 | ||||
| -rw-r--r-- | embassy-executor/src/arch/spin.rs | 4 | ||||
| -rw-r--r-- | embassy-executor/src/arch/std.rs | 19 | ||||
| -rw-r--r-- | embassy-executor/src/arch/wasm.rs | 4 |
7 files changed, 33 insertions, 17 deletions
diff --git a/embassy-executor/src/arch/avr.rs b/embassy-executor/src/arch/avr.rs index 70085d04d..a841afe15 100644 --- a/embassy-executor/src/arch/avr.rs +++ b/embassy-executor/src/arch/avr.rs | |||
| @@ -10,11 +10,11 @@ mod thread { | |||
| 10 | pub use embassy_executor_macros::main_avr as main; | 10 | pub use embassy_executor_macros::main_avr as main; |
| 11 | use portable_atomic::{AtomicBool, Ordering}; | 11 | use portable_atomic::{AtomicBool, Ordering}; |
| 12 | 12 | ||
| 13 | use crate::{raw, Spawner}; | 13 | use crate::{Spawner, raw}; |
| 14 | 14 | ||
| 15 | static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); | 15 | static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); |
| 16 | 16 | ||
| 17 | #[export_name = "__pender"] | 17 | #[unsafe(export_name = "__pender")] |
| 18 | fn __pender(_context: *mut ()) { | 18 | fn __pender(_context: *mut ()) { |
| 19 | SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); | 19 | SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); |
| 20 | } | 20 | } |
diff --git a/embassy-executor/src/arch/cortex_ar.rs b/embassy-executor/src/arch/cortex_ar.rs index f9e2f3f7c..ce572738a 100644 --- a/embassy-executor/src/arch/cortex_ar.rs +++ b/embassy-executor/src/arch/cortex_ar.rs | |||
| @@ -1,7 +1,10 @@ | |||
| 1 | #[cfg(arm_profile = "legacy")] | ||
| 2 | compile_error!("`arch-cortex-ar` does not support the legacy ARM profile, WFE/SEV are not available."); | ||
| 3 | |||
| 1 | #[cfg(feature = "executor-interrupt")] | 4 | #[cfg(feature = "executor-interrupt")] |
| 2 | compile_error!("`executor-interrupt` is not supported with `arch-cortex-ar`."); | 5 | compile_error!("`executor-interrupt` is not supported with `arch-cortex-ar`."); |
| 3 | 6 | ||
| 4 | #[export_name = "__pender"] | 7 | #[unsafe(export_name = "__pender")] |
| 5 | #[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))] | 8 | #[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))] |
| 6 | fn __pender(context: *mut ()) { | 9 | fn __pender(context: *mut ()) { |
| 7 | // `context` is always `usize::MAX` created by `Executor::run`. | 10 | // `context` is always `usize::MAX` created by `Executor::run`. |
| @@ -10,7 +13,7 @@ fn __pender(context: *mut ()) { | |||
| 10 | #[cfg(feature = "executor-thread")] | 13 | #[cfg(feature = "executor-thread")] |
| 11 | // Try to make Rust optimize the branching away if we only use thread mode. | 14 | // Try to make Rust optimize the branching away if we only use thread mode. |
| 12 | if !cfg!(feature = "executor-interrupt") || context == THREAD_PENDER { | 15 | if !cfg!(feature = "executor-interrupt") || context == THREAD_PENDER { |
| 13 | cortex_ar::asm::sev(); | 16 | aarch32_cpu::asm::sev(); |
| 14 | return; | 17 | return; |
| 15 | } | 18 | } |
| 16 | } | 19 | } |
| @@ -23,10 +26,10 @@ mod thread { | |||
| 23 | 26 | ||
| 24 | use core::marker::PhantomData; | 27 | use core::marker::PhantomData; |
| 25 | 28 | ||
| 26 | use cortex_ar::asm::wfe; | 29 | use aarch32_cpu::asm::wfe; |
| 27 | pub use embassy_executor_macros::main_cortex_ar as main; | 30 | pub use embassy_executor_macros::main_cortex_ar as main; |
| 28 | 31 | ||
| 29 | use crate::{raw, Spawner}; | 32 | use crate::{Spawner, raw}; |
| 30 | 33 | ||
| 31 | /// Thread mode executor, using WFE/SEV. | 34 | /// Thread mode executor, using WFE/SEV. |
| 32 | /// | 35 | /// |
diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs index 1c9ddd8a0..1ce96d1d5 100644 --- a/embassy-executor/src/arch/cortex_m.rs +++ b/embassy-executor/src/arch/cortex_m.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #[export_name = "__pender"] | 1 | #[unsafe(export_name = "__pender")] |
| 2 | #[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))] | 2 | #[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))] |
| 3 | fn __pender(context: *mut ()) { | 3 | fn __pender(context: *mut ()) { |
| 4 | unsafe { | 4 | unsafe { |
| @@ -53,7 +53,7 @@ mod thread { | |||
| 53 | 53 | ||
| 54 | pub use embassy_executor_macros::main_cortex_m as main; | 54 | pub use embassy_executor_macros::main_cortex_m as main; |
| 55 | 55 | ||
| 56 | use crate::{raw, Spawner}; | 56 | use crate::{Spawner, raw}; |
| 57 | 57 | ||
| 58 | /// Thread mode executor, using WFE/SEV. | 58 | /// Thread mode executor, using WFE/SEV. |
| 59 | /// | 59 | /// |
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs index 01e63a9fd..c70c1344a 100644 --- a/embassy-executor/src/arch/riscv32.rs +++ b/embassy-executor/src/arch/riscv32.rs | |||
| @@ -10,12 +10,12 @@ mod thread { | |||
| 10 | 10 | ||
| 11 | pub use embassy_executor_macros::main_riscv as main; | 11 | pub use embassy_executor_macros::main_riscv as main; |
| 12 | 12 | ||
| 13 | use crate::{raw, Spawner}; | 13 | use crate::{Spawner, raw}; |
| 14 | 14 | ||
| 15 | /// global atomic used to keep track of whether there is work to do since sev() is not available on RISCV | 15 | /// global atomic used to keep track of whether there is work to do since sev() is not available on RISCV |
| 16 | static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); | 16 | static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); |
| 17 | 17 | ||
| 18 | #[export_name = "__pender"] | 18 | #[unsafe(export_name = "__pender")] |
| 19 | fn __pender(_context: *mut ()) { | 19 | fn __pender(_context: *mut ()) { |
| 20 | SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); | 20 | SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); |
| 21 | } | 21 | } |
diff --git a/embassy-executor/src/arch/spin.rs b/embassy-executor/src/arch/spin.rs index 340023620..49f3356a6 100644 --- a/embassy-executor/src/arch/spin.rs +++ b/embassy-executor/src/arch/spin.rs | |||
| @@ -9,9 +9,9 @@ mod thread { | |||
| 9 | 9 | ||
| 10 | pub use embassy_executor_macros::main_spin as main; | 10 | pub use embassy_executor_macros::main_spin as main; |
| 11 | 11 | ||
| 12 | use crate::{raw, Spawner}; | 12 | use crate::{Spawner, raw}; |
| 13 | 13 | ||
| 14 | #[export_name = "__pender"] | 14 | #[unsafe(export_name = "__pender")] |
| 15 | fn __pender(_context: *mut ()) {} | 15 | fn __pender(_context: *mut ()) {} |
| 16 | 16 | ||
| 17 | /// Spin Executor | 17 | /// Spin Executor |
diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs index b02b15988..d4057144e 100644 --- a/embassy-executor/src/arch/std.rs +++ b/embassy-executor/src/arch/std.rs | |||
| @@ -10,9 +10,9 @@ mod thread { | |||
| 10 | 10 | ||
| 11 | pub use embassy_executor_macros::main_std as main; | 11 | pub use embassy_executor_macros::main_std as main; |
| 12 | 12 | ||
| 13 | use crate::{raw, Spawner}; | 13 | use crate::{Spawner, raw}; |
| 14 | 14 | ||
| 15 | #[export_name = "__pender"] | 15 | #[unsafe(export_name = "__pender")] |
| 16 | fn __pender(context: *mut ()) { | 16 | fn __pender(context: *mut ()) { |
| 17 | let signaler: &'static Signaler = unsafe { std::mem::transmute(context) }; | 17 | let signaler: &'static Signaler = unsafe { std::mem::transmute(context) }; |
| 18 | signaler.signal() | 18 | signaler.signal() |
| @@ -55,11 +55,24 @@ mod thread { | |||
| 55 | /// | 55 | /// |
| 56 | /// This function never returns. | 56 | /// This function never returns. |
| 57 | pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { | 57 | pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { |
| 58 | self.run_until(init, || false); | ||
| 59 | unreachable!() | ||
| 60 | } | ||
| 61 | |||
| 62 | /// Run the executor until a flag is raised. | ||
| 63 | /// | ||
| 64 | /// This function is identical to `Executor::run()` apart from offering a `done` flag to stop execution. | ||
| 65 | pub fn run_until(&'static mut self, init: impl FnOnce(Spawner), mut done: impl FnMut() -> bool) { | ||
| 58 | init(self.inner.spawner()); | 66 | init(self.inner.spawner()); |
| 59 | 67 | ||
| 60 | loop { | 68 | loop { |
| 61 | unsafe { self.inner.poll() }; | 69 | unsafe { self.inner.poll() }; |
| 62 | self.signaler.wait() | 70 | |
| 71 | if done() { | ||
| 72 | break; | ||
| 73 | } | ||
| 74 | |||
| 75 | self.signaler.wait(); | ||
| 63 | } | 76 | } |
| 64 | } | 77 | } |
| 65 | } | 78 | } |
diff --git a/embassy-executor/src/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs index f9d0f935c..d2ff2fe51 100644 --- a/embassy-executor/src/arch/wasm.rs +++ b/embassy-executor/src/arch/wasm.rs | |||
| @@ -13,9 +13,9 @@ mod thread { | |||
| 13 | use wasm_bindgen::prelude::*; | 13 | use wasm_bindgen::prelude::*; |
| 14 | 14 | ||
| 15 | use crate::raw::util::UninitCell; | 15 | use crate::raw::util::UninitCell; |
| 16 | use crate::{raw, Spawner}; | 16 | use crate::{Spawner, raw}; |
| 17 | 17 | ||
| 18 | #[export_name = "__pender"] | 18 | #[unsafe(export_name = "__pender")] |
| 19 | fn __pender(context: *mut ()) { | 19 | fn __pender(context: *mut ()) { |
| 20 | let signaler: &'static WasmContext = unsafe { std::mem::transmute(context) }; | 20 | let signaler: &'static WasmContext = unsafe { std::mem::transmute(context) }; |
| 21 | let _ = signaler.promise.then(unsafe { signaler.closure.as_mut() }); | 21 | let _ = signaler.promise.then(unsafe { signaler.closure.as_mut() }); |
