Skip to content

Commit

Permalink
Only update on schedul
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 28, 2024
1 parent dcc2c29 commit 91e1b3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
9 changes: 2 additions & 7 deletions embassy-executor/src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,6 @@ impl SyncExecutor {

#[cfg(feature = "rtos-trace")]
trace::task_exec_end();

// Enqueue or update into timer_queue
#[cfg(feature = "integrated-timers")]
self.timer_queue.update(p);
});

#[cfg(feature = "integrated-timers")]
Expand Down Expand Up @@ -598,10 +594,9 @@ struct TimerQueue;
impl embassy_time_queue_driver::TimerQueue for TimerQueue {
fn schedule_wake(&'static self, at: u64, waker: &core::task::Waker) {
let task = waker::task_from_waker(waker);
let task = task.header();
unsafe {
let expires_at = task.next_expiration.get();
task.next_expiration.set(expires_at.min(at));
let executor = task.header().executor.get().unwrap_unchecked();
executor.timer_queue.update(task, at);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions embassy-executor/src/raw/timer_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ impl TimerQueue {
}
}

pub(crate) unsafe fn update(&self, p: TaskRef) {
pub(crate) unsafe fn update(&self, p: TaskRef, at: u64) {
let task = p.header();
if task.next_expiration.get() != u64::MAX {
if at < task.next_expiration.get() {
task.next_expiration.set(at);
critical_section::with(|cs| {
if task.state.timer_enqueue() {
let prev = self.head.borrow(cs).replace(Some(p));
Expand Down

0 comments on commit 91e1b3f

Please sign in to comment.