devela/work/sync/
atomic.rs

1// devela::work::sync::atomic
2//
3//! Atomic types.
4//!
5//! It also re-exports the [`Atomic`] type from the
6//! [`atomic`](https://docs.rs/atomic) crate,
7//! and some useful definitions from `core`.
8//
9
10#[cfg(feature = "dep_portable_atomic")]
11use crate::DOC_ATOMIC_CORE_PORTABLE;
12use crate::{reexport, TAG_ATOMIC, TAG_ATOMIC_CORE_PORTABLE};
13
14/* from `core` */
15
16// enums
17reexport! { rust: core::sync::atomic,
18    tag: TAG_ATOMIC!(),
19    doc: "Atomic memory ordering.",
20    @Ordering as AtomicOrdering
21}
22
23// functions
24reexport! { rust: core::sync::atomic,
25    tag: TAG_ATOMIC!(),
26    doc: "An atomic fence.",
27    @fence as atomic_fence
28}
29reexport! { rust: core::sync::atomic,
30    tag: TAG_ATOMIC!(),
31    doc: "A compiler memory fence.",
32    @compiler_fence as atomic_compiler_fence
33}
34
35/* from the `atomic` crate */
36
37reexport! { "dep_atomic", "atomic", atomic,
38    tag: TAG_ATOMIC!(),
39    doc: "A generic atomic wrapper type.",
40    Atomic
41}
42
43/* from `portable-atomic` */
44
45reexport! { "dep_portable_atomic", "portable-atomic", portable_atomic,
46    tag: TAG_ATOMIC!(),
47    doc: "A thread-safe floating-point type.",
48    AtomicF32, AtomicF64
49}
50reexport! { "dep_portable_atomic", "portable-atomic", portable_atomic,
51    tag: TAG_ATOMIC!(),
52    doc: "A thread-safe signed integer type.",
53    AtomicI128
54}
55reexport! { "dep_portable_atomic", "portable-atomic", portable_atomic,
56    tag: TAG_ATOMIC!(),
57    doc: "A thread-safe unsigned integer type.",
58    AtomicU128
59}
60
61/* from either `portable-atomic` or `core` */
62
63#[doc = TAG_ATOMIC!()]
64#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
65#[doc = "A thread-safe signed integer type.\n\n"]
66#[doc = DOC_ATOMIC_CORE_PORTABLE!()]
67#[cfg(feature = "dep_portable_atomic")]
68pub use crate::_dep::portable_atomic::{AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize};
69
70#[doc = TAG_ATOMIC!()]
71#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
72#[doc = "A thread-safe unsigned integer type.\n\n"]
73#[doc = DOC_ATOMIC_CORE_PORTABLE!()]
74#[cfg(feature = "dep_portable_atomic")]
75pub use crate::_dep::portable_atomic::{AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize};
76
77#[doc = TAG_ATOMIC!()]
78#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
79#[cfg(all(not(feature = "dep_portable_atomic"), target_has_atomic = "8"))]
80pub use core::sync::atomic::{AtomicI8, AtomicU8};
81//
82#[doc = TAG_ATOMIC!()]
83#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
84#[cfg(all(not(feature = "dep_portable_atomic"), target_has_atomic = "16"))]
85pub use core::sync::atomic::{AtomicI16, AtomicU16};
86//
87#[doc = TAG_ATOMIC!()]
88#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
89#[cfg(all(not(feature = "dep_portable_atomic"), target_has_atomic = "32"))]
90pub use core::sync::atomic::{AtomicI32, AtomicU32};
91//
92#[doc = TAG_ATOMIC!()]
93#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
94#[cfg(all(not(feature = "dep_portable_atomic"), target_has_atomic = "64"))]
95pub use core::sync::atomic::{AtomicI64, AtomicU64};
96//
97// WAIT: [integer_atomics](https://github.com/rust-lang/rust/issues/99069)
98// #[doc = TAG_ATOMIC!()]
99// #[doc = TAG_ATOMIC_CORE_PORTABLE!()]
100// #[cfg(all(not(feature = "dep_portable_atomic"), target_has_atomic = "128"))]
101// pub use core::sync::atomic::{AtomicI128, AtomicU128};
102//
103#[doc = TAG_ATOMIC!()]
104#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
105#[cfg(all(not(feature = "dep_portable_atomic"), target_has_atomic = "ptr"))]
106pub use core::sync::atomic::{AtomicIsize, AtomicUsize};
107
108#[doc = TAG_ATOMIC!()]
109#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
110#[cfg(feature = "dep_portable_atomic")]
111pub use crate::_dep::portable_atomic::AtomicPtr;
112//
113#[doc = TAG_ATOMIC!()]
114#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
115#[cfg(all(not(feature = "dep_portable_atomic"), target_has_atomic = "ptr"))]
116pub use core::sync::atomic::AtomicPtr;
117
118#[doc = TAG_ATOMIC!()]
119#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
120#[cfg(feature = "dep_portable_atomic")]
121pub use crate::_dep::portable_atomic::AtomicBool;
122//
123#[doc = TAG_ATOMIC!()]
124#[doc = TAG_ATOMIC_CORE_PORTABLE!()]
125#[cfg(not(feature = "dep_portable_atomic"))]
126pub use core::sync::atomic::AtomicBool;
127
128/* impl ConstDefaut */
129
130#[cfg(feature = "dep_atomic")]
131mod impl_const_default_for_atomic {
132    #![allow(clippy::declare_interior_mutable_const, unused_imports)]
133    use crate::{impl_cdef, ConstDefault};
134    impl_cdef![<T: ConstDefault> Self::new(T::DEFAULT) => super::Atomic<T>];
135}
136#[cfg(feature = "dep_portable_atomic")]
137mod impl_const_default_for_portable_atomic {
138    #![allow(clippy::declare_interior_mutable_const, unused_imports)]
139    use crate::{impl_cdef, ConstDefault};
140
141    // without core alternatives:
142    impl_cdef![Self::new(f32::DEFAULT) => super::AtomicF32];
143    impl_cdef![Self::new(f64::DEFAULT) => super::AtomicF64];
144
145    // with core alternatives:
146    impl_cdef![Self::new(i8::DEFAULT) => super::AtomicI8];
147    impl_cdef![Self::new(u8::DEFAULT) => super::AtomicU8];
148    impl_cdef![Self::new(i16::DEFAULT) => super::AtomicI16];
149    impl_cdef![Self::new(u16::DEFAULT) => super::AtomicU16];
150    impl_cdef![Self::new(i32::DEFAULT) => super::AtomicI32];
151    impl_cdef![Self::new(u32::DEFAULT) => super::AtomicU32];
152    impl_cdef![Self::new(i64::DEFAULT) => super::AtomicI64];
153    impl_cdef![Self::new(u64::DEFAULT) => super::AtomicU64];
154    impl_cdef![Self::new(i128::DEFAULT) => super::AtomicI128];
155    impl_cdef![Self::new(u128::DEFAULT) => super::AtomicU128];
156    impl_cdef![Self::new(isize::DEFAULT) => super::AtomicIsize];
157    impl_cdef![Self::new(usize::DEFAULT) => super::AtomicUsize];
158    impl_cdef![<T> Self::new(<*mut T>::DEFAULT) => super::AtomicPtr<T>];
159}
160#[cfg(not(feature = "dep_portable_atomic"))]
161mod impl_const_default_for_core {
162    #![allow(clippy::declare_interior_mutable_const, unused_imports)]
163    use crate::{impl_cdef, ConstDefault};
164
165    #[cfg(target_has_atomic = "8")]
166    impl_cdef![Self::new(i8::DEFAULT) => super::AtomicI8];
167    #[cfg(target_has_atomic = "8")]
168    impl_cdef![Self::new(u8::DEFAULT) => super::AtomicU8];
169    #[cfg(target_has_atomic = "16")]
170    impl_cdef![Self::new(i16::DEFAULT) => super::AtomicI16];
171    #[cfg(target_has_atomic = "16")]
172    impl_cdef![Self::new(u16::DEFAULT) => super::AtomicU16];
173    #[cfg(target_has_atomic = "32")]
174    impl_cdef![Self::new(i32::DEFAULT) => super::AtomicI32];
175    #[cfg(target_has_atomic = "32")]
176    impl_cdef![Self::new(u32::DEFAULT) => super::AtomicU32];
177    #[cfg(target_has_atomic = "64")]
178    impl_cdef![Self::new(i64::DEFAULT) => super::AtomicI64];
179    #[cfg(target_has_atomic = "64")]
180    impl_cdef![Self::new(u64::DEFAULT) => super::AtomicU64];
181
182    // WAIT: [AtomicU128/AtomicI128 not shown](https://github.com/rust-lang/rust/issues/130539)
183    // WAIT: [integer_atomics](https://github.com/rust-lang/rust/issues/99069)
184    // #[cfg(target_has_atomic = "128")]
185    // #[cfg(feature = "nightly_atomics")]
186    // impl_cdef![Self::new(i128::DEFAULT) => super::AtomicI128];
187    // #[cfg(target_has_atomic = "128")]
188    // #[cfg(feature = "nightly_atomics")]
189    // impl_cdef![Self::new(u128::DEFAULT) => super::AtomicU128];
190
191    #[cfg(target_has_atomic = "ptr")]
192    impl_cdef![Self::new(isize::DEFAULT) => super::AtomicIsize];
193    #[cfg(target_has_atomic = "ptr")]
194    impl_cdef![Self::new(usize::DEFAULT) => super::AtomicUsize];
195    #[cfg(target_has_atomic = "ptr")]
196    impl_cdef![<T> Self::new(<*mut T>::DEFAULT) => super::AtomicPtr<T>];
197}