1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Sleep queue implementation that used to build up synchronization primitives.

use crate::task::{SleepKind, TaskAdapter};
use core::ops::{Deref, DerefMut};
use intrusive_collections::LinkedList;

pub(crate) struct SleepQueue(LinkedList<TaskAdapter>);

impl SleepQueue {
    pub const fn new() -> Self {
        Self(LinkedList::new(TaskAdapter::NEW))
    }

    pub fn peek_front(&self) -> Option<SleepKind> {
        let task = self.0.front().get()?;
        Some(task.get_sleep_kind())
    }
}

impl Deref for SleepQueue {
    type Target = LinkedList<TaskAdapter>;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl DerefMut for SleepQueue {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}

impl Drop for SleepQueue {
    fn drop(&mut self) {
        assert!(self.0.is_empty(), "sleeping task dropped");
    }
}