portable-atomic
Portable atomic types.
- Provide all atomic integer types (
Atomic{I,U}{8,16,32,64}) for all targets that can use atomic CAS. (i.e., all targets that can usestd, and most no-std targets) - (optional) Provide
Atomic{I,U}128. (lock-free on x86_64 and aarch64 at Rust 1.59+) - (optional) Provide
AtomicF{32,64}.
- Provide atomic load/store for targets where atomic is not available at all in the standard library. (riscv without A-extension, msp430, avr)
- (optional, single-core only) Provide atomic CAS for targets where atomic CAS is not available in the standard library. (thumbv6m, riscv without A-extension, msp430, avr)
Optional features
-
fallback(enabled by default) Enable fallback implementations. -
i128ProvideAtomic{I,U}128.Note:
- 128-bit atomic operations are only available for x86_64 and aarch64 at Rust 1.59+, otherwise the fallback implementation is used.
- On x86_64, when
cmpxchg16btarget feature is not enabled at compile time, this uses the fallback implementation.cmpxchg16bis enabled by default only on macOS. - This implicitly enables the
fallbackfeature.
If you need support for dynamic CPU feature detection, use the
i128-dynamicfeature. -
i128-dynamicSimilar to thei128feature, but tries to usecmpxchg16bin more cases based on dynamic CPU feature detection.Note:
- Dynamic detection is only enabled in nightly, otherwise it works the same as the
i128feature. - When
cmpxchg16btarget feature is enabled at compile time, this works exactly the same as thei128feature. - If both
i128andi128-dynamicfeatures are used in the dependency graph,i128-dynamictakes precedence. - This is compatible with no-std (as with all features except
stdandparking_lot).
- Dynamic detection is only enabled in nightly, otherwise it works the same as the
-
floatProvideAtomicF{32,64}. Note that most offetch_*operations of atomic floats are implemented using CAS loops, which can be slower than equivalent operations of atomic integers.
-
stdUsestd. -
serdeImplementserde::{Serialize,Deserialize}for atomic types.Note:
- The MSRV when this feature enables depends on the MSRV of serde.
-
parking_lotUse parking_lot in global locks of fallback implementation.Note:
- This is not compatible with no-std.
- The MSRV when this feature enables depends on the MSRV of parking_lot.
Optional cfg
-
--cfg portable_atomic_unsafe_assume_single_coreAssume that the target is single-core. When this cfg is enabled, this crate provides atomic CAS for targets where atomic CAS is not available in the standard library.Note: This cfg is
unsafe, and enabling this cfg for multi-core systems is unsound.This is intentionally not an optional feature. If this is an optional feature, dependencies can implicitly enable the feature, resulting in the use of unsound code without the end-user being aware of it.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.