Skip to main content

embassy_time_queue_utils/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3#![warn(missing_docs)]
4
5use core::task::Waker;
6
7pub mod queue_generic;
8pub mod queue_integrated;
9
10#[cfg(feature = "_generic-queue")]
11type QueueImpl = queue_generic::Queue;
12#[cfg(not(feature = "_generic-queue"))]
13type QueueImpl = queue_integrated::Queue;
14
15/// The default timer queue, configured by the crate's features.
16///
17/// If any of the `generic-queue-X` features are enabled, this implements a generic
18/// timer queue of capacity X. Otherwise, it implements an integrated timer queue.
19#[derive(Debug)]
20pub struct Queue {
21    queue: QueueImpl,
22}
23
24impl Queue {
25    /// Creates a new timer queue.
26    pub const fn new() -> Self {
27        Self {
28            queue: QueueImpl::new(),
29        }
30    }
31
32    /// Schedules a task to run at a specific time, and returns whether any changes were made.
33    ///
34    /// If this function returns `true`, the caller should find the next expiration time and set
35    /// a new alarm for that time.
36    pub fn schedule_wake(&mut self, at: u64, waker: &Waker) -> bool {
37        self.queue.schedule_wake(at, waker)
38    }
39
40    /// Dequeues expired timers and returns the next alarm time.
41    pub fn next_expiration(&mut self, now: u64) -> u64 {
42        self.queue.next_expiration(now)
43    }
44}