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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use crate::loom::sync::atomic::AtomicUsize;
use crate::runtime::thread_pool::{queue, Shared};
use crate::task::{self, Task};
use crate::util::FastRand;
use std::cell::Cell;
#[derive(Debug)]
pub(super) struct Owned {
pub(super) generation: AtomicUsize,
pub(super) tick: Cell<u16>,
pub(super) is_running: Cell<bool>,
pub(super) is_searching: Cell<bool>,
pub(super) defer_notification: Cell<bool>,
pub(super) did_submit_task: Cell<bool>,
pub(super) rand: FastRand,
pub(super) work_queue: queue::Worker<Shared>,
pub(super) owned_tasks: task::OwnedList<Shared>,
}
impl Owned {
pub(super) fn new(work_queue: queue::Worker<Shared>, rand: FastRand) -> Owned {
Owned {
generation: AtomicUsize::new(0),
tick: Cell::new(1),
is_running: Cell::new(true),
is_searching: Cell::new(false),
defer_notification: Cell::new(false),
did_submit_task: Cell::new(false),
rand,
work_queue,
owned_tasks: task::OwnedList::new(),
}
}
pub(super) fn submit_local(&self, task: Task<Shared>) -> bool {
let ret = self.work_queue.push(task);
if self.defer_notification.get() {
self.did_submit_task.set(true);
false
} else {
ret
}
}
pub(super) fn submit_local_yield(&self, task: Task<Shared>) {
self.work_queue.push_yield(task);
}
pub(super) fn bind_task(&mut self, task: &Task<Shared>) {
self.owned_tasks.insert(task);
}
pub(super) fn release_task(&mut self, task: &Task<Shared>) {
self.owned_tasks.remove(task);
}
}