crossbeam_utils/atomic/
consume.rs1#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
2use crate::primitive::sync::atomic::compiler_fence;
3#[cfg(not(crossbeam_no_atomic))]
4use core::sync::atomic::Ordering;
5
6pub trait AtomicConsume {
8 type Val;
10
11 fn load_consume(&self) -> Self::Val;
27}
28
29#[cfg(not(crossbeam_no_atomic))]
30#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
31macro_rules! impl_consume {
32 () => {
33 #[inline]
34 fn load_consume(&self) -> Self::Val {
35 let result = self.load(Ordering::Relaxed);
36 compiler_fence(Ordering::Acquire);
37 result
38 }
39 };
40}
41
42#[cfg(not(crossbeam_no_atomic))]
43#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
44macro_rules! impl_consume {
45 () => {
46 #[inline]
47 fn load_consume(&self) -> Self::Val {
48 self.load(Ordering::Acquire)
49 }
50 };
51}
52
53macro_rules! impl_atomic {
54 ($atomic:ident, $val:ty) => {
55 #[cfg(not(crossbeam_no_atomic))]
56 impl AtomicConsume for core::sync::atomic::$atomic {
57 type Val = $val;
58 impl_consume!();
59 }
60 #[cfg(crossbeam_loom)]
61 impl AtomicConsume for loom::sync::atomic::$atomic {
62 type Val = $val;
63 impl_consume!();
64 }
65 };
66}
67
68impl_atomic!(AtomicBool, bool);
69impl_atomic!(AtomicUsize, usize);
70impl_atomic!(AtomicIsize, isize);
71impl_atomic!(AtomicU8, u8);
72impl_atomic!(AtomicI8, i8);
73impl_atomic!(AtomicU16, u16);
74impl_atomic!(AtomicI16, i16);
75impl_atomic!(AtomicU32, u32);
76impl_atomic!(AtomicI32, i32);
77#[cfg(not(crossbeam_no_atomic_64))]
78impl_atomic!(AtomicU64, u64);
79#[cfg(not(crossbeam_no_atomic_64))]
80impl_atomic!(AtomicI64, i64);
81
82#[cfg(not(crossbeam_no_atomic))]
83impl<T> AtomicConsume for core::sync::atomic::AtomicPtr<T> {
84 type Val = *mut T;
85 impl_consume!();
86}
87
88#[cfg(crossbeam_loom)]
89impl<T> AtomicConsume for loom::sync::atomic::AtomicPtr<T> {
90 type Val = *mut T;
91 impl_consume!();
92}