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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#![allow(clippy::missing_inline_in_public_items)]
use core::sync::atomic::Ordering;
use serde::{
de::{Deserialize, Deserializer},
ser::{Serialize, Serializer},
};
macro_rules! atomic_impl {
($($ty:ident),*) => {$(
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl Serialize for crate::$ty {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.load(Ordering::SeqCst).serialize(serializer)
}
}
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> Deserialize<'de> for crate::$ty {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
Deserialize::deserialize(deserializer).map(Self::new)
}
}
)*};
}
atomic_impl!(AtomicBool, AtomicIsize, AtomicUsize);
atomic_impl!(AtomicI8, AtomicU8, AtomicI16, AtomicU16);
#[cfg(any(not(target_pointer_width = "16"), portable_atomic_unsafe_assume_single_core))]
atomic_impl!(AtomicI32, AtomicU32);
#[cfg_attr(
not(portable_atomic_cfg_target_has_atomic),
cfg(any(
all(feature = "fallback", not(portable_atomic_no_atomic_cas)),
not(portable_atomic_no_atomic_64),
portable_atomic_unsafe_assume_single_core
))
)]
#[cfg_attr(
portable_atomic_cfg_target_has_atomic,
cfg(any(
all(feature = "fallback", target_has_atomic = "ptr"),
target_has_atomic = "64",
target_pointer_width = "64",
portable_atomic_unsafe_assume_single_core
))
)]
atomic_impl!(AtomicI64, AtomicU64);
#[cfg(feature = "i128")]
#[cfg_attr(
not(portable_atomic_cfg_target_has_atomic),
cfg(any(not(portable_atomic_no_atomic_cas), portable_atomic_unsafe_assume_single_core))
)]
#[cfg_attr(
portable_atomic_cfg_target_has_atomic,
cfg(any(target_has_atomic = "ptr", portable_atomic_unsafe_assume_single_core))
)]
atomic_impl!(AtomicI128, AtomicU128);
#[cfg(feature = "float")]
#[cfg(any(not(target_pointer_width = "16"), portable_atomic_unsafe_assume_single_core))]
atomic_impl!(AtomicF32);
#[cfg(feature = "float")]
#[cfg_attr(
not(portable_atomic_cfg_target_has_atomic),
cfg(any(
all(feature = "fallback", not(portable_atomic_no_atomic_cas)),
not(portable_atomic_no_atomic_64),
portable_atomic_unsafe_assume_single_core
))
)]
#[cfg_attr(
portable_atomic_cfg_target_has_atomic,
cfg(any(
all(feature = "fallback", target_has_atomic = "ptr"),
target_has_atomic = "64",
target_pointer_width = "64",
portable_atomic_unsafe_assume_single_core
))
)]
atomic_impl!(AtomicF64);