1use crate::runtime::task;
2
3pub(crate) struct Synced {
4 /// True if the queue is closed.
5 pub(super) is_closed: bool,
6
7 /// Linked-list head.
8 pub(super) head: Option<task::RawTask>,
9
10 /// Linked-list tail.
11 pub(super) tail: Option<task::RawTask>,
12}
13
14unsafe impl Send for Synced {}
15unsafe impl Sync for Synced {}
16
17impl Synced {
18 pub(super) fn pop<T: 'static>(&mut self) -> Option<task::Notified<T>> {
19 let task: RawTask = self.head?;
20
21 self.head = unsafe { task.get_queue_next() };
22
23 if self.head.is_none() {
24 self.tail = None;
25 }
26
27 unsafe { task.set_queue_next(val:None) };
28
29 // safety: a `Notified` is pushed into the queue and now it is popped!
30 Some(unsafe { task::Notified::from_raw(ptr:task) })
31 }
32}
33