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
use futures::task::ArcWake;
use std::sync::{
    atomic::{AtomicBool, AtomicU64, Ordering},
    Arc,
};
#[derive(Default)]
pub struct CountsClones(Arc<AtomicU64>);
impl CountsClones {
    
    pub fn clone_count(&self) -> u64 {
        self.0.load(Ordering::Relaxed)
    }
}
impl Clone for CountsClones {
    fn clone(&self) -> Self {
        self.0.fetch_add(1, Ordering::Relaxed);
        Self(self.0.clone())
    }
}
pub struct BoolWaker(AtomicBool);
impl BoolWaker {
    
    pub fn new() -> Arc<Self> {
        Arc::new(Self(AtomicBool::new(false)))
    }
    
    pub fn is_woken(&self) -> bool {
        self.0.swap(false, Ordering::Relaxed)
    }
}
impl ArcWake for BoolWaker {
    fn wake_by_ref(arc_self: &Arc<Self>) {
        arc_self.0.store(true, Ordering::Relaxed);
    }
}