diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-11-09 10:15:11 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-09 10:15:11 +0000 |
| commit | b4929032d5f013985becb88faf9b847236afe172 (patch) | |
| tree | bbdd1ccb6ebda2e4be8362709a8188ae1bed895a /src/tq.rs | |
| parent | 4f3c5baf49bde675dfa8faf6e5311d38cbb5d654 (diff) | |
| parent | 5ab5112271a9dbef6d875ad89706fc726e126b95 (diff) | |
Merge #547
547: New monotonic trait r=AfoHT a=korken89
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'src/tq.rs')
| -rw-r--r-- | src/tq.rs | 27 |
1 files changed, 6 insertions, 21 deletions
@@ -1,19 +1,7 @@ -use crate::{ - time::{Clock, Instant}, - Monotonic, -}; +use crate::Monotonic; use core::cmp::Ordering; use heapless::sorted_linked_list::{LinkedIndexU16, Min, SortedLinkedList}; -#[inline(always)] -fn unwrapper<T, E>(val: Result<T, E>) -> T { - if let Ok(v) = val { - v - } else { - unreachable!("Your monotonic is not infallible") - } -} - pub struct TimerQueue<Mono, Task, const N: usize>( pub SortedLinkedList<NotReady<Mono, Task>, LinkedIndexU16, Min, N>, ) @@ -87,7 +75,7 @@ where &mut self, marker: u32, new_marker: u32, - instant: Instant<Mono>, + instant: Mono::Instant, pend_handler: F, ) -> Result<(), ()> { if let Some(mut val) = self.0.find_mut(|nr| nr.marker == marker) { @@ -111,23 +99,20 @@ where mono.clear_compare_flag(); if let Some(instant) = self.0.peek().map(|p| p.instant) { - let now = unwrapper(Clock::try_now(mono)); - // This if statement is like this and not <= due to a bug in embedded-time - if instant < now || instant == now { + if instant <= mono.now() { // task became ready let nr = unsafe { self.0.pop_unchecked() }; Some((nr.task, nr.index)) } else { // Set compare - mono.set_compare(&instant); + mono.set_compare(instant); // Double check that the instant we set is really in the future, else // 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 // guard against this. - let now = unwrapper(Clock::try_now(mono)); - if instant < now || instant == now { + if instant <= mono.now() { let nr = unsafe { self.0.pop_unchecked() }; Some((nr.task, nr.index)) @@ -153,7 +138,7 @@ where Mono: Monotonic, { pub index: u8, - pub instant: Instant<Mono>, + pub instant: Mono::Instant, pub task: Task, pub marker: u32, } |
