aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/arch
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-11-14 22:32:48 +0100
committerDario Nieuwenhuis <[email protected]>2023-11-15 18:43:27 +0100
commitbef9b7a8539c3dddb1cf6ab46db161f1ca56b1a1 (patch)
tree6d15736eec0029c13093bee120bd2189aa9537ac /embassy-executor/src/arch
parent50a983fd9b8f10fa5153757593e9f8cfccc902ac (diff)
executor: remove atomic-polyfill.
Diffstat (limited to 'embassy-executor/src/arch')
-rw-r--r--embassy-executor/src/arch/cortex_m.rs21
-rw-r--r--embassy-executor/src/arch/riscv32.rs2
2 files changed, 10 insertions, 13 deletions
diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs
index fde862f3c..55299c94f 100644
--- a/embassy-executor/src/arch/cortex_m.rs
+++ b/embassy-executor/src/arch/cortex_m.rs
@@ -115,12 +115,12 @@ mod thread {
115pub use interrupt::*; 115pub use interrupt::*;
116#[cfg(feature = "executor-interrupt")] 116#[cfg(feature = "executor-interrupt")]
117mod interrupt { 117mod interrupt {
118 use core::cell::UnsafeCell; 118 use core::cell::{Cell, UnsafeCell};
119 use core::mem::MaybeUninit; 119 use core::mem::MaybeUninit;
120 120
121 use atomic_polyfill::{AtomicBool, Ordering};
122 use cortex_m::interrupt::InterruptNumber; 121 use cortex_m::interrupt::InterruptNumber;
123 use cortex_m::peripheral::NVIC; 122 use cortex_m::peripheral::NVIC;
123 use critical_section::Mutex;
124 124
125 use crate::raw; 125 use crate::raw;
126 126
@@ -146,7 +146,7 @@ mod interrupt {
146 /// It is somewhat more complex to use, it's recommended to use the thread-mode 146 /// It is somewhat more complex to use, it's recommended to use the thread-mode
147 /// [`Executor`] instead, if it works for your use case. 147 /// [`Executor`] instead, if it works for your use case.
148 pub struct InterruptExecutor { 148 pub struct InterruptExecutor {
149 started: AtomicBool, 149 started: Mutex<Cell<bool>>,
150 executor: UnsafeCell<MaybeUninit<raw::Executor>>, 150 executor: UnsafeCell<MaybeUninit<raw::Executor>>,
151 } 151 }
152 152
@@ -158,7 +158,7 @@ mod interrupt {
158 #[inline] 158 #[inline]
159 pub const fn new() -> Self { 159 pub const fn new() -> Self {
160 Self { 160 Self {
161 started: AtomicBool::new(false), 161 started: Mutex::new(Cell::new(false)),
162 executor: UnsafeCell::new(MaybeUninit::uninit()), 162 executor: UnsafeCell::new(MaybeUninit::uninit()),
163 } 163 }
164 } 164 }
@@ -167,7 +167,8 @@ mod interrupt {
167 /// 167 ///
168 /// # Safety 168 /// # Safety
169 /// 169 ///
170 /// You MUST call this from the interrupt handler, and from nowhere else. 170 /// - You MUST call this from the interrupt handler, and from nowhere else.
171 /// - You must not call this before calling `start()`.
171 pub unsafe fn on_interrupt(&'static self) { 172 pub unsafe fn on_interrupt(&'static self) {
172 let executor = unsafe { (&*self.executor.get()).assume_init_ref() }; 173 let executor = unsafe { (&*self.executor.get()).assume_init_ref() };
173 executor.poll(); 174 executor.poll();
@@ -196,11 +197,7 @@ mod interrupt {
196 /// do it after. 197 /// do it after.
197 /// 198 ///
198 pub fn start(&'static self, irq: impl InterruptNumber) -> crate::SendSpawner { 199 pub fn start(&'static self, irq: impl InterruptNumber) -> crate::SendSpawner {
199 if self 200 if critical_section::with(|cs| self.started.borrow(cs).replace(true)) {
200 .started
201 .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
202 .is_err()
203 {
204 panic!("InterruptExecutor::start() called multiple times on the same executor."); 201 panic!("InterruptExecutor::start() called multiple times on the same executor.");
205 } 202 }
206 203
@@ -222,10 +219,10 @@ mod interrupt {
222 /// This returns a [`SendSpawner`] you can use to spawn tasks on this 219 /// This returns a [`SendSpawner`] you can use to spawn tasks on this
223 /// executor. 220 /// executor.
224 /// 221 ///
225 /// This MUST only be called on an executor that has already been spawned. 222 /// This MUST only be called on an executor that has already been started.
226 /// The function will panic otherwise. 223 /// The function will panic otherwise.
227 pub fn spawner(&'static self) -> crate::SendSpawner { 224 pub fn spawner(&'static self) -> crate::SendSpawner {
228 if !self.started.load(Ordering::Acquire) { 225 if !critical_section::with(|cs| self.started.borrow(cs).get()) {
229 panic!("InterruptExecutor::spawner() called on uninitialized executor."); 226 panic!("InterruptExecutor::spawner() called on uninitialized executor.");
230 } 227 }
231 let executor = unsafe { (&*self.executor.get()).assume_init_ref() }; 228 let executor = unsafe { (&*self.executor.get()).assume_init_ref() };
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index e5c0ff2ec..6814e7844 100644
--- a/embassy-executor/src/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
@@ -7,9 +7,9 @@ pub use thread::*;
7mod thread { 7mod thread {
8 use core::marker::PhantomData; 8 use core::marker::PhantomData;
9 9
10 use atomic_polyfill::{AtomicBool, Ordering};
11 #[cfg(feature = "nightly")] 10 #[cfg(feature = "nightly")]
12 pub use embassy_macros::main_riscv as main; 11 pub use embassy_macros::main_riscv as main;
12 use portable_atomic::{AtomicBool, Ordering};
13 13
14 use crate::{raw, Spawner}; 14 use crate::{raw, Spawner};
15 15