Portable atomic types including support for 128-bit atomics, atomic float, etc.
Atomic{I,U}{8,16,32,64}
) for all targets that can use atomic CAS. (i.e., all targets that can use std
, and most no-std targets)AtomicI128
and AtomicU128
.AtomicF32
and AtomicF64
. (optional)
AtomicPtr::fetch_*
, AtomicBool::fetch_not
.Native 128-bit atomic operations are available on x86_64 (Rust 1.59+), aarch64 (Rust 1.59+), powerpc64 (le or pwr8+, nightly only), and s390x (nightly only), otherwise the fallback implementation is used.
On x86_64, when the outline-atomics
optional feature is not enabled and cmpxchg16b
target feature is not enabled at compile-time, this uses the fallback implementation. cmpxchg16b
target feature is enabled by default only on macOS.
They are usually implemented using inline assembly, and when using Miri or ThreadSanitizer that do not support inline assembly, core intrinsics are used instead of inline assembly if possible.
See this list for details.
fallback
(enabled by default)
Enable fallback implementations.
Disabling this allows only atomic types for which the platform natively supports atomic operations.
outline-atomics
Enable run-time CPU feature detection.
This allows maintaining support for older CPUs while using features that are not supported on older CPUs, such as CMPXCHG16B (x8664) and FEATLSE (aarch64).
Note:
std
).See also this list.
float
Provide AtomicF{32,64}
.
Note that most of fetch_*
operations of atomic floats are implemented using CAS loops, which can be slower than equivalent operations of atomic integers.
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.)
Enabling this cfg for targets that have atomic CAS will result in a compile error.
ARMv6-M (thumbv6m), pre-v6 ARM (e.g., thumbv4t), RISC-V without A-extension are currently supported. See [#33] for support of multi-core systems.
Since all MSP430 and AVR are single-core, we always provide atomic CAS for them without this cfg.
Feel free to submit an issue if your target is not supported yet.
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.