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
use std::fmt;
use std::sync::atomic::{AtomicUsize, Ordering};
#[derive(Eq, PartialEq, Clone, Copy, Hash, Debug)]
pub struct TaskId(pub(crate) usize);
impl TaskId {
pub(crate) fn generate() -> TaskId {
static COUNTER: AtomicUsize = AtomicUsize::new(1);
let id = COUNTER.fetch_add(1, Ordering::Relaxed);
if id > usize::max_value() / 2 {
std::process::abort();
}
TaskId(id)
}
}
impl fmt::Display for TaskId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}