Skip to main content

tokio/runtime/time_alt/
registration_queue.rs

1use super::{Entry, EntryHandle, RegistrationQueueEntry};
2use crate::util::linked_list;
3
4type EntryList = linked_list::LinkedList<RegistrationQueueEntry, Entry>;
5
6/// A queue of entries that need to be registered in the timer wheel.
7#[derive(Debug)]
8pub(crate) struct RegistrationQueue {
9    list: EntryList,
10}
11
12impl Drop for RegistrationQueue {
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 RegistrationQueue {
22    pub(crate) fn new() -> Self {
23        Self {
24            list: EntryList::new(),
25        }
26    }
27
28    /// # Safety
29    ///
30    /// Behavior is undefined if any of the following conditions are violated:
31    ///
32    /// - [`Entry::extra_pointers`] of `hdl` must not being used.
33    pub(crate) unsafe fn push_front(&mut self, hdl: EntryHandle) {
34        self.list.push_front(hdl);
35    }
36
37    pub(crate) fn pop_front(&mut self) -> Option<EntryHandle> {
38        self.list.pop_front()
39    }
40}
41
42#[cfg(test)]
43mod tests;