Skip to main content

tokio/runtime/time_alt/
wake_queue.rs

1use super::{Entry, EntryHandle, WakeQueueEntry};
2use crate::util::linked_list;
3
4type EntryList = linked_list::LinkedList<WakeQueueEntry, Entry>;
5
6/// A queue of entries that need to be woken up.
7#[derive(Debug)]
8pub(crate) struct WakeQueue {
9    list: EntryList,
10}
11
12impl Drop for WakeQueue {
13    fn drop(&mut self) {
14        // drain all entries without waking them up
15        while let Some(hdl) = self.list.pop_front() {
16            drop(hdl);
17        }
18    }
19}
20
21impl WakeQueue {
22    pub(crate) fn new() -> Self {
23        Self {
24            list: EntryList::new(),
25        }
26    }
27
28    pub(crate) fn is_empty(&self) -> bool {
29        self.list.is_empty()
30    }
31
32    /// # Safety
33    ///
34    /// Behavior is undefined if any of the following conditions are violated:
35    ///
36    /// - [`Entry::extra_pointers`] of `hdl` must not being used.
37    pub(crate) unsafe fn push_front(&mut self, hdl: EntryHandle) {
38        self.list.push_front(hdl);
39    }
40
41    /// Wakes all entries in the wake queue.
42    pub(crate) fn wake_all(mut self) {
43        while let Some(hdl) = self.list.pop_front() {
44            hdl.wake();
45        }
46    }
47}
48
49#[cfg(test)]
50mod tests;