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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use crate::distributor::Distributor;
use crate::run_queue::{Injector, Stealer};
use crate::sleepers::Sleepers;
use crate::worker;
use lazy_static::lazy_static;
use lightproc::prelude::*;
use std::future::Future;
pub fn spawn<F, T>(future: F, stack: ProcStack) -> RecoverableHandle<T>
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
self::get().spawn(future, stack)
}
#[derive(Debug)]
pub struct Pool {
pub(crate) injector: Injector<LightProc>,
pub(crate) stealers: Vec<Stealer<LightProc>>,
pub(crate) sleepers: Sleepers,
}
impl Pool {
pub fn recover_async_thread() {
unimplemented!()
}
pub fn spawn<F, T>(&self, future: F, stack: ProcStack) -> RecoverableHandle<T>
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
let _child_id = stack.get_pid() as u64;
let _parent_id = worker::get_proc_stack(|t| t.get_pid() as u64).unwrap_or(0);
let (task, handle) = LightProc::recoverable(future, worker::schedule, stack);
task.schedule();
handle
}
}
#[inline]
pub fn get() -> &'static Pool {
lazy_static! {
static ref POOL: Pool = {
let distributor = Distributor::new();
let stealers = distributor.assign();
Pool {
injector: Injector::new(),
stealers,
sleepers: Sleepers::new(),
}
};
}
&*POOL
}