aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2024-12-13 21:45:52 +0100
committerDániel Buga <[email protected]>2024-12-15 18:50:00 +0100
commit5c4983236c2e68b6ba2ce325ed77ec39466fc3b6 (patch)
tree9e3e2bc1f374d494fb6f83ad523654ae2a52b2b9 /embassy-executor/src
parent2f2e2c6031a1abaecdac5ed2febe109e647fe6fd (diff)
Make sure an exited task does not get stuck in a timer queue
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/raw/mod.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index 2feaab155..b825fa6c2 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -192,7 +192,17 @@ impl<F: Future + 'static> TaskStorage<F> {
192 match future.poll(&mut cx) { 192 match future.poll(&mut cx) {
193 Poll::Ready(_) => { 193 Poll::Ready(_) => {
194 this.future.drop_in_place(); 194 this.future.drop_in_place();
195
196 // Mark this task to be timer queued, to prevent re-queueing it.
197 this.raw.state.timer_enqueue();
198
199 // Now mark the task as not spawned, so that
200 // - it can be spawned again once it has been removed from the timer queue
201 // - it can not be timer-queued again
195 this.raw.state.despawn(); 202 this.raw.state.despawn();
203
204 // Schedule the task by hand in the past, so it runs immediately.
205 unsafe { _embassy_time_schedule_wake(0, &waker) }
196 } 206 }
197 Poll::Pending => {} 207 Poll::Pending => {}
198 } 208 }
@@ -211,6 +221,10 @@ impl<F: Future + 'static> TaskStorage<F> {
211 } 221 }
212} 222}
213 223
224extern "Rust" {
225 fn _embassy_time_schedule_wake(at: u64, waker: &core::task::Waker);
226}
227
214/// An uninitialized [`TaskStorage`]. 228/// An uninitialized [`TaskStorage`].
215pub struct AvailableTask<F: Future + 'static> { 229pub struct AvailableTask<F: Future + 'static> {
216 task: &'static TaskStorage<F>, 230 task: &'static TaskStorage<F>,