uefi_async/nano_alloc/
task.rs

1use alloc::boxed::Box;
2use core::pin::Pin;
3
4/// A node in a linked-list representing an asynchronous task.
5///
6/// # Lifetimes
7/// * `'curr`: The lifetime of the future's internal data.
8/// * `'next`: The lifetime of the reference to the next node in the list.
9///
10/// tip: `'curr` is longer than `'next`.
11pub struct TaskNode<'curr, 'next> {
12    /// The pinned asynchronous computation to be executed.
13    pub future: Pin<Box<dyn Future<Output = ()> + 'curr>>,
14    /// The execution interval, converted into hardware ticks.
15    pub interval: u64,
16    /// The timestamp (in ticks) when this task should run again.
17    pub next_run_time: u64,
18    /// Link to the next task in the executor's chain.
19    pub next: Option<&'next mut TaskNode<'curr, 'next>>,
20}
21impl<'curr, 'next> TaskNode<'curr, 'next> {
22    /// Creates a new `TaskNode` with a given future and frequency.
23    ///
24    /// Note: `freq` is initially the user-requested frequency and is
25    /// recalculated into an interval when added to an [`Executor`].
26    #[inline]
27    pub fn new(future: Pin<Box<dyn Future<Output = ()> + 'curr>>, freq: u64) -> Self {
28        Self { future, interval: freq, next_run_time: 0, next: None }
29    }
30}