aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-executor/CHANGELOG.md2
-rw-r--r--embassy-executor/src/arch/avr.rs4
-rw-r--r--embassy-executor/src/arch/cortex_m.rs6
-rw-r--r--embassy-executor/src/arch/riscv32.rs4
-rw-r--r--embassy-executor/src/arch/spin.rs4
-rw-r--r--embassy-executor/src/arch/std.rs4
-rw-r--r--embassy-executor/src/arch/wasm.rs4
-rw-r--r--embassy-executor/src/raw/mod.rs21
-rw-r--r--embassy-executor/tests/test.rs4
-rw-r--r--embassy-stm32/src/low_power.rs12
10 files changed, 56 insertions, 9 deletions
diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md
index eae5e3c2b..00b1bef28 100644
--- a/embassy-executor/CHANGELOG.md
+++ b/embassy-executor/CHANGELOG.md
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7 7
8## Unreleased 8## Unreleased
9 9
10- Only set integrated-timers callbacks once per executor. 10- `raw::Executor` now has an `fn initialize` that must be called once before starting to poll it.
11 11
12## 0.6.3 - 2024-11-12 12## 0.6.3 - 2024-11-12
13 13
diff --git a/embassy-executor/src/arch/avr.rs b/embassy-executor/src/arch/avr.rs
index 70085d04d..7f9ed4421 100644
--- a/embassy-executor/src/arch/avr.rs
+++ b/embassy-executor/src/arch/avr.rs
@@ -53,6 +53,10 @@ mod thread {
53 /// 53 ///
54 /// This function never returns. 54 /// This function never returns.
55 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { 55 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
56 unsafe {
57 self.inner.initialize();
58 }
59
56 init(self.inner.spawner()); 60 init(self.inner.spawner());
57 61
58 loop { 62 loop {
diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs
index 5c517e0a2..0c2af88a6 100644
--- a/embassy-executor/src/arch/cortex_m.rs
+++ b/embassy-executor/src/arch/cortex_m.rs
@@ -98,6 +98,9 @@ mod thread {
98 /// 98 ///
99 /// This function never returns. 99 /// This function never returns.
100 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { 100 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
101 unsafe {
102 self.inner.initialize();
103 }
101 init(self.inner.spawner()); 104 init(self.inner.spawner());
102 105
103 loop { 106 loop {
@@ -207,6 +210,9 @@ mod interrupt {
207 } 210 }
208 211
209 let executor = unsafe { (&*self.executor.get()).assume_init_ref() }; 212 let executor = unsafe { (&*self.executor.get()).assume_init_ref() };
213 unsafe {
214 executor.initialize();
215 }
210 216
211 unsafe { NVIC::unmask(irq) } 217 unsafe { NVIC::unmask(irq) }
212 218
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index 01e63a9fd..715e5f3cf 100644
--- a/embassy-executor/src/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
@@ -54,6 +54,10 @@ mod thread {
54 /// 54 ///
55 /// This function never returns. 55 /// This function never returns.
56 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { 56 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
57 unsafe {
58 self.inner.initialize();
59 }
60
57 init(self.inner.spawner()); 61 init(self.inner.spawner());
58 62
59 loop { 63 loop {
diff --git a/embassy-executor/src/arch/spin.rs b/embassy-executor/src/arch/spin.rs
index 340023620..54c7458b3 100644
--- a/embassy-executor/src/arch/spin.rs
+++ b/embassy-executor/src/arch/spin.rs
@@ -48,6 +48,10 @@ mod thread {
48 /// 48 ///
49 /// This function never returns. 49 /// This function never returns.
50 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { 50 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
51 unsafe {
52 self.inner.initialize();
53 }
54
51 init(self.inner.spawner()); 55 init(self.inner.spawner());
52 56
53 loop { 57 loop {
diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs
index b02b15988..948c7711b 100644
--- a/embassy-executor/src/arch/std.rs
+++ b/embassy-executor/src/arch/std.rs
@@ -55,6 +55,10 @@ 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 unsafe {
59 self.inner.initialize();
60 }
61
58 init(self.inner.spawner()); 62 init(self.inner.spawner());
59 63
60 loop { 64 loop {
diff --git a/embassy-executor/src/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs
index f9d0f935c..35025f11f 100644
--- a/embassy-executor/src/arch/wasm.rs
+++ b/embassy-executor/src/arch/wasm.rs
@@ -71,6 +71,10 @@ mod thread {
71 /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) 71 /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe)
72 pub fn start(&'static mut self, init: impl FnOnce(Spawner)) { 72 pub fn start(&'static mut self, init: impl FnOnce(Spawner)) {
73 unsafe { 73 unsafe {
74 self.inner.initialize();
75 }
76
77 unsafe {
74 let executor = &self.inner; 78 let executor = &self.inner;
75 let future = Closure::new(move |_| { 79 let future = Closure::new(move |_| {
76 executor.poll(); 80 executor.poll();
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index e8a5b8970..ebabee1ba 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -328,7 +328,7 @@ impl SyncExecutor {
328 #[cfg(feature = "integrated-timers")] 328 #[cfg(feature = "integrated-timers")]
329 let alarm = unsafe { unwrap!(embassy_time_driver::allocate_alarm()) }; 329 let alarm = unsafe { unwrap!(embassy_time_driver::allocate_alarm()) };
330 330
331 let this = Self { 331 Self {
332 run_queue: RunQueue::new(), 332 run_queue: RunQueue::new(),
333 pender, 333 pender,
334 334
@@ -336,12 +336,12 @@ impl SyncExecutor {
336 timer_queue: timer_queue::TimerQueue::new(), 336 timer_queue: timer_queue::TimerQueue::new(),
337 #[cfg(feature = "integrated-timers")] 337 #[cfg(feature = "integrated-timers")]
338 alarm, 338 alarm,
339 }; 339 }
340 }
340 341
342 pub(crate) unsafe fn initialize(&'static self) {
341 #[cfg(feature = "integrated-timers")] 343 #[cfg(feature = "integrated-timers")]
342 embassy_time_driver::set_alarm_callback(this.alarm, Self::alarm_callback, &this as *const _ as *mut ()); 344 embassy_time_driver::set_alarm_callback(self.alarm, Self::alarm_callback, self as *const _ as *mut ());
343
344 this
345 } 345 }
346 346
347 /// Enqueue a task in the task queue 347 /// Enqueue a task in the task queue
@@ -494,6 +494,15 @@ impl Executor {
494 } 494 }
495 } 495 }
496 496
497 /// Initializes the executor.
498 ///
499 /// # Safety
500 ///
501 /// This function must be called once before any other method is called.
502 pub unsafe fn initialize(&'static self) {
503 self.inner.initialize();
504 }
505
497 /// Spawn a task in this executor. 506 /// Spawn a task in this executor.
498 /// 507 ///
499 /// # Safety 508 /// # Safety
@@ -518,6 +527,8 @@ impl Executor {
518 /// 527 ///
519 /// # Safety 528 /// # Safety
520 /// 529 ///
530 /// You must call `initialize` before calling this method.
531 ///
521 /// You must NOT call `poll` reentrantly on the same executor. 532 /// You must NOT call `poll` reentrantly on the same executor.
522 /// 533 ///
523 /// In particular, note that `poll` may call the pender synchronously. Therefore, you 534 /// In particular, note that `poll` may call the pender synchronously. Therefore, you
diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs
index 348cc7dc4..8054bf7eb 100644
--- a/embassy-executor/tests/test.rs
+++ b/embassy-executor/tests/test.rs
@@ -40,6 +40,10 @@ fn setup() -> (&'static Executor, Trace) {
40 let trace = Trace::new(); 40 let trace = Trace::new();
41 let context = Box::leak(Box::new(trace.clone())) as *mut _ as *mut (); 41 let context = Box::leak(Box::new(trace.clone())) as *mut _ as *mut ();
42 let executor = &*Box::leak(Box::new(Executor::new(context))); 42 let executor = &*Box::leak(Box::new(Executor::new(context)));
43 unsafe {
44 executor.initialize();
45 }
46
43 (executor, trace) 47 (executor, trace)
44} 48}
45 49
diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs
index a779b8a09..d74221864 100644
--- a/embassy-stm32/src/low_power.rs
+++ b/embassy-stm32/src/low_power.rs
@@ -155,7 +155,9 @@ impl Executor {
155 time_driver: get_driver(), 155 time_driver: get_driver(),
156 }); 156 });
157 157
158 EXECUTOR.as_mut().unwrap() 158 let executor = EXECUTOR.as_mut().unwrap();
159
160 executor
159 }) 161 })
160 } 162 }
161 163
@@ -241,11 +243,15 @@ impl Executor {
241 /// 243 ///
242 /// This function never returns. 244 /// This function never returns.
243 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { 245 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
244 init(unsafe { EXECUTOR.as_mut().unwrap() }.inner.spawner()); 246 let executor = unsafe { EXECUTOR.as_mut().unwrap() };
247 unsafe {
248 executor.inner.initialize();
249 }
250 init(executor.inner.spawner());
245 251
246 loop { 252 loop {
247 unsafe { 253 unsafe {
248 EXECUTOR.as_mut().unwrap().inner.poll(); 254 executor.inner.poll();
249 self.configure_pwr(); 255 self.configure_pwr();
250 asm!("wfe"); 256 asm!("wfe");
251 }; 257 };