-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
list.rs
33 lines (27 loc) · 923 Bytes
/
list.rs
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
use crate::loom::sync::Mutex;
use crate::runtime::task::Task;
use crate::util::linked_list::{Link, LinkedList};
pub(crate) struct OwnedTasks<S: 'static> {
list: Mutex<LinkedList<Task<S>, <Task<S> as Link>::Target>>,
}
impl<S: 'static> OwnedTasks<S> {
pub(crate) fn new() -> Self {
Self {
list: Mutex::new(LinkedList::new()),
}
}
pub(crate) fn push_front(&self, task: Task<S>) {
self.list.lock().push_front(task);
}
pub(crate) fn pop_back(&self) -> Option<Task<S>> {
self.list.lock().pop_back()
}
/// The caller must ensure that if the provided task is stored in a
/// linked list, then it is in this linked list.
pub(crate) unsafe fn remove(&self, task: &Task<S>) -> Option<Task<S>> {
self.list.lock().remove(task.header().into())
}
pub(crate) fn is_empty(&self) -> bool {
self.list.lock().is_empty()
}
}