From 1087f2ee64a5be1aedf3b702ccb5d86cc64708d9 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 11 Mar 2021 19:12:02 +0100 Subject: Added interface for cancel/reschedule Use wrapping add for marker No need to store handle to queue Remove unnecessary `SpawnHandle::new` Fix test Updated interface to follow proposal --- src/tq.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/tq.rs') diff --git a/src/tq.rs b/src/tq.rs index 063bbd8..f341d8c 100644 --- a/src/tq.rs +++ b/src/tq.rs @@ -5,6 +5,15 @@ use crate::{ use core::cmp::Ordering; use heapless::{binary_heap::Min, ArrayLength, BinaryHeap}; +#[inline] +fn unwrapper(val: Result) -> T { + if let Ok(v) = val { + v + } else { + unreachable!("Your monotonic is not infallible") + } +} + pub struct TimerQueue(pub BinaryHeap, N, Min>) where Mono: Monotonic, @@ -66,15 +75,6 @@ where self.0.is_empty() } - #[inline] - fn unwrapper(val: Result) -> T { - if let Ok(v) = val { - v - } else { - unreachable!("Your monotonic is not infallible") - } - } - /// Dequeue a task from the TimerQueue #[inline] pub fn dequeue(&mut self, disable_interrupt: F, mono: &mut Mono) -> Option<(Task, u8)> @@ -84,7 +84,7 @@ where mono.clear_compare_flag(); if let Some(instant) = self.0.peek().map(|p| p.instant) { - if instant <= Self::unwrapper(Clock::try_now(mono)) { + if instant <= unwrapper(Clock::try_now(mono)) { // task became ready let nr = unsafe { self.0.pop_unchecked() }; @@ -97,7 +97,7 @@ where // 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. - if instant <= Self::unwrapper(Clock::try_now(mono)) { + if instant <= unwrapper(Clock::try_now(mono)) { let nr = unsafe { self.0.pop_unchecked() }; Some((nr.task, nr.index)) @@ -125,6 +125,7 @@ where pub index: u8, pub instant: Instant, pub task: Task, + pub marker: u32, } impl Eq for NotReady -- cgit v1.2.3