blob: 5377f4398f2cdbc35fb56a89069ef9e71c5f6e07 (
plain) (
blame)
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
|
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
pub type SharedAbortSignal = Arc<AbortSignal>;
#[allow(clippy::module_name_repetitions)]
pub struct AbortSignal {
ctrlc: AtomicBool,
ctrld: AtomicBool,
}
impl AbortSignal {
pub fn new() -> SharedAbortSignal {
Arc::new(Self {
ctrlc: AtomicBool::new(false),
ctrld: AtomicBool::new(false),
})
}
pub fn aborted(&self) -> bool {
if self.aborted_ctrlc() {
return true;
}
if self.aborted_ctrld() {
return true;
}
false
}
pub fn aborted_ctrlc(&self) -> bool {
self.ctrlc.load(Ordering::SeqCst)
}
pub fn aborted_ctrld(&self) -> bool {
self.ctrld.load(Ordering::SeqCst)
}
pub fn reset(&self) {
self.ctrlc.store(false, Ordering::SeqCst);
self.ctrld.store(false, Ordering::SeqCst);
}
pub fn set_ctrlc(&self) {
self.ctrlc.store(true, Ordering::SeqCst);
}
pub fn set_ctrld(&self) {
self.ctrld.store(true, Ordering::SeqCst);
}
}
|