tokio/runtime/scheduler/inject/
synced.rs

1#![cfg_attr(
2    any(not(all(tokio_unstable, feature = "full")), target_family = "wasm"),
3    allow(dead_code)
4)]
5
6use crate::runtime::task;
7
8pub(crate) struct Synced {
9    /// True if the queue is closed.
10    pub(super) is_closed: bool,
11
12    /// Linked-list head.
13    pub(super) head: Option<task::RawTask>,
14
15    /// Linked-list tail.
16    pub(super) tail: Option<task::RawTask>,
17}
18
19unsafe impl Send for Synced {}
20unsafe impl Sync for Synced {}
21
22impl Synced {
23    pub(super) fn pop<T: 'static>(&mut self) -> Option<task::Notified<T>> {
24        let task = self.head?;
25
26        self.head = unsafe { task.get_queue_next() };
27
28        if self.head.is_none() {
29            self.tail = None;
30        }
31
32        unsafe { task.set_queue_next(None) };
33
34        // safety: a `Notified` is pushed into the queue and now it is popped!
35        Some(unsafe { task::Notified::from_raw(task) })
36    }
37
38    pub(crate) fn is_empty(&self) -> bool {
39        self.head.is_none()
40    }
41}