mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
Fixed a bug in the timer queue
When a waker was dequeued, and it had already exipired, the dequeue was not re-run to set a proper new compare match for the monotonic. This is now fixed.
This commit is contained in:
parent
4ccc7d3dcb
commit
613b3c59fc
1 changed files with 48 additions and 39 deletions
33
src/tq.rs
33
src/tq.rs
|
@ -136,8 +136,7 @@ where
|
||||||
instant: Mono::Instant,
|
instant: Mono::Instant,
|
||||||
mono: &mut Mono,
|
mono: &mut Mono,
|
||||||
) -> Option<(Task, u8)> {
|
) -> Option<(Task, u8)> {
|
||||||
let now = mono.now();
|
if instant <= mono.now() {
|
||||||
if instant <= now {
|
|
||||||
// task became ready
|
// task became ready
|
||||||
let nr = unsafe { self.task_queue.pop_unchecked() };
|
let nr = unsafe { self.task_queue.pop_unchecked() };
|
||||||
Some((nr.task, nr.index))
|
Some((nr.task, nr.index))
|
||||||
|
@ -149,7 +148,7 @@ where
|
||||||
// dequeue. If the monotonic is fast enough it can happen that from the
|
// dequeue. If the monotonic is fast enough it can happen that from the
|
||||||
// read of now to the set of the compare, the time can overflow. This is to
|
// read of now to the set of the compare, the time can overflow. This is to
|
||||||
// guard against this.
|
// guard against this.
|
||||||
if instant <= now {
|
if instant <= mono.now() {
|
||||||
let nr = unsafe { self.task_queue.pop_unchecked() };
|
let nr = unsafe { self.task_queue.pop_unchecked() };
|
||||||
Some((nr.task, nr.index))
|
Some((nr.task, nr.index))
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,12 +157,15 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dequeue_waker_queue(&mut self, instant: Mono::Instant, mono: &mut Mono) {
|
fn dequeue_waker_queue(&mut self, instant: Mono::Instant, mono: &mut Mono) -> bool {
|
||||||
let now = mono.now();
|
let mut did_wake = false;
|
||||||
if instant <= now {
|
|
||||||
|
if instant <= mono.now() {
|
||||||
// Task became ready, wake the waker
|
// Task became ready, wake the waker
|
||||||
if let Some(v) = self.waker_queue.pop() {
|
if let Some(v) = self.waker_queue.pop() {
|
||||||
v.val.waker.wake_by_ref()
|
v.val.waker.wake_by_ref();
|
||||||
|
|
||||||
|
did_wake = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Set compare
|
// Set compare
|
||||||
|
@ -173,12 +175,16 @@ where
|
||||||
// dequeue. If the monotonic is fast enough it can happen that from the
|
// dequeue. If the monotonic is fast enough it can happen that from the
|
||||||
// read of now to the set of the compare, the time can overflow. This is to
|
// read of now to the set of the compare, the time can overflow. This is to
|
||||||
// guard against this.
|
// guard against this.
|
||||||
if instant <= now {
|
if instant <= mono.now() {
|
||||||
if let Some(v) = self.waker_queue.pop() {
|
if let Some(v) = self.waker_queue.pop() {
|
||||||
v.val.waker.wake_by_ref()
|
v.val.waker.wake_by_ref();
|
||||||
|
|
||||||
|
did_wake = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
did_wake
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dequeue a task from the ``TimerQueue``
|
/// Dequeue a task from the ``TimerQueue``
|
||||||
|
@ -188,6 +194,7 @@ where
|
||||||
{
|
{
|
||||||
mono.clear_compare_flag();
|
mono.clear_compare_flag();
|
||||||
|
|
||||||
|
loop {
|
||||||
let tq = self.task_queue.peek().map(|p| p.instant);
|
let tq = self.task_queue.peek().map(|p| p.instant);
|
||||||
let wq = self.waker_queue.peek().map(|p| p.instant);
|
let wq = self.waker_queue.peek().map(|p| p.instant);
|
||||||
|
|
||||||
|
@ -224,10 +231,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
if dequeue_task {
|
if dequeue_task {
|
||||||
self.dequeue_task_queue(instant, mono)
|
return self.dequeue_task_queue(instant, mono);
|
||||||
|
} else if !self.dequeue_waker_queue(instant, mono) {
|
||||||
|
return None;
|
||||||
} else {
|
} else {
|
||||||
self.dequeue_waker_queue(instant, mono);
|
// Run the dequeue again
|
||||||
None
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue