aboutsummaryrefslogtreecommitdiff
path: root/embassy-time-queue-driver/src/lib.rs
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2024-12-09 08:43:57 +0100
committerDániel Buga <[email protected]>2024-12-13 21:20:57 +0100
commitec96395d084d5edc8be25ddaea8547e2ebd447a6 (patch)
treeb1edf825c8d67013df3cec1283376a7558951a3f /embassy-time-queue-driver/src/lib.rs
parentd45ea43892198484b5f6dcea4c351dc11d226cc4 (diff)
Prevent task from respawning while in the timer queue
Diffstat (limited to 'embassy-time-queue-driver/src/lib.rs')
-rw-r--r--embassy-time-queue-driver/src/lib.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/embassy-time-queue-driver/src/lib.rs b/embassy-time-queue-driver/src/lib.rs
index 0c78921ed..2d5fd449a 100644
--- a/embassy-time-queue-driver/src/lib.rs
+++ b/embassy-time-queue-driver/src/lib.rs
@@ -73,6 +73,20 @@ extern "Rust" {
73 73
74/// Schedule the given waker to be woken at `at`. 74/// Schedule the given waker to be woken at `at`.
75pub fn schedule_wake(at: u64, waker: &Waker) { 75pub fn schedule_wake(at: u64, waker: &Waker) {
76 #[cfg(feature = "integrated-timers")]
77 {
78 use embassy_executor::raw::task_from_waker;
79 use embassy_executor::raw::timer_queue::TimerEnqueueOperation;
80 // The very first thing we must do, before we even access the timer queue, is to
81 // mark the task a TIMER_QUEUED. This ensures that the task that is being scheduled
82 // can not be respawn while we are accessing the timer queue.
83 let task = task_from_waker(waker);
84 if unsafe { task.timer_enqueue() } == TimerEnqueueOperation::Ignore {
85 // We are not allowed to enqueue the task in the timer queue. This is because the
86 // task is not spawned, and so it makes no sense to schedule it.
87 return;
88 }
89 }
76 unsafe { _embassy_time_schedule_wake(at, waker) } 90 unsafe { _embassy_time_schedule_wake(at, waker) }
77} 91}
78 92