aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2024-11-19 15:59:31 +0100
committerDániel Buga <[email protected]>2024-11-19 16:25:17 +0100
commit8ebe059ecb311ee949f92dde33f2cb8d972b0f7b (patch)
tree4906d12e2a2f141dded4defd84650b165e2da51d /embassy-executor/src
parentff02ee1a221122ede6e30a94156c42e22b400578 (diff)
Add initialize
Diffstat (limited to 'embassy-executor/src')
-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
7 files changed, 42 insertions, 5 deletions
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