|
2 | 2 | #![doc = include_str!("../README.md")] |
3 | 3 | #![warn(missing_docs)] |
4 | 4 |
|
5 | | -#[cfg(feature = "_generic-queue")] |
| 5 | +use core::task::Waker; |
| 6 | + |
6 | 7 | pub mod queue_generic; |
7 | | -#[cfg(not(feature = "_generic-queue"))] |
8 | 8 | pub mod queue_integrated; |
9 | 9 |
|
10 | 10 | #[cfg(feature = "_generic-queue")] |
11 | | -pub use queue_generic::Queue; |
| 11 | +type QueueImpl = queue_generic::Queue; |
12 | 12 | #[cfg(not(feature = "_generic-queue"))] |
13 | | -pub use queue_integrated::Queue; |
| 13 | +type 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)] |
| 20 | +pub struct Queue { |
| 21 | + queue: QueueImpl, |
| 22 | +} |
| 23 | + |
| 24 | +impl 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 called 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 | +} |
0 commit comments