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
pub use core::sync::atomic::Ordering;
pub trait AtomicallySized: Sized {
type AtomicVersion: Atomic<Self>;
}
pub trait Atomic<T>: Send + Sync + Sized
where
T: Sized,
{
unsafe fn from_raw(val: &T) -> &Self {
&*(val as *const T as *const Self)
}
fn new(val: T) -> Self;
fn store(&self, val: T, order: Ordering);
fn load(&self, order: Ordering) -> T;
fn swap(&self, val: T, order: Ordering) -> T;
fn get_mut(&mut self) -> &mut T;
fn into_inner(self) -> T;
fn compare_and_swap(&self, current: T, new: T, order: Ordering) -> T;
fn compare_exchange(
&self,
current: T,
new: T,
success: Ordering,
failure: Ordering,
) -> Result<T, T>;
fn compare_exchange_weak(
&self,
current: T,
new: T,
success: Ordering,
failure: Ordering,
) -> Result<T, T>;
}
pub trait AtomicNumeric<T>: Atomic<T> {
fn fetch_add(&self, val: T, order: Ordering) -> T;
fn fetch_sub(&self, val: T, order: Ordering) -> T;
}
pub trait AtomicBitwise<T>: Atomic<T> {
fn fetch_and(&self, val: T, order: Ordering) -> T;
fn fetch_or(&self, val: T, order: Ordering) -> T;
fn fetch_xor(&self, val: T, order: Ordering) -> T;
fn fetch_nand(&self, val: T, order: Ordering) -> T;
}