Expand description
atomic-int provides atomics for additional integers, such as C/FFI types
like c_int
.
For integer types that are aliases of primitive integers that have built-in Rust atomics, this crate simply re-exports those atomics. Otherwise, this crate provides a spinlock-based fallback implementation with a compatible API.
This crate also provides types that directly correspond with Rust’s
standard atomics, like AtomicU64
, with the difference that the fallback
implementation will similarly be used for any such atomics that are not
supported on a given platform. Thus, all atomics provided by this crate are
available on all platforms1 in some form—either the built-in or fallback
implementation.
§Crate features
Types that directly correspond with Rust’s standard atomics like
AtomicU64
are available with the feature primitives
(enabled by
default). This includes AtomicPtr
, even though it isn’t exactly an
integer.
Atomic C integer types like AtomicCInt
and AtomicCUlong
are
available with the feature c
(enabled by default). For more granularity,
a separate feature exists for each C integer (e.g., c_int
and c_ulong
).
The spinlock-based fallback implementation can cause deadlocks with signal
handlers. To avoid this, enable the feature signal
, which blocks incoming
signals while the lock is held. This feature is Unix-specific; on
non-Unix-like operating systems it is a no-op.
atomic-int can optionally depend on libc
. If this dependency is
enabled, atomic-int will use the C integer types from libc
instead of
core::ffi
. This should not make a noticeable difference, but it can
decrease the minimum required Rust version, as C integer types were added
to core::ffi
only in version 1.64. The feature signal
always enables
libc
.
For development purposes, the feature force-fallback
is provided. This
forces the fallback implementation to be used for all atomics, which can
help you ensure your program doesn’t rely on functionality only provided by
the native atomic types. It should not normally be enabled outside of
testing.
§Use without std
This crate is no_std
when libc
is not enabled.
As long as the platform supports
AtomicBool
, and compare-and-swap operations onAtomicBool
, which are required for the fallback implementation. ↩
Structs§
- Atomic
Fallback doc
- An example fallback implementation of an atomic integer.
- Atomic
Fallback Ptr doc
- An example fallback implementation of an atomic pointer.
Type Aliases§
- Atomic
Bool primitives
- An atomic
bool
. - AtomicC
Char c_char
- An atomic
c_char
. - AtomicC
Int c_int
- An atomic
c_int
. - AtomicC
Long c_long
- An atomic
c_long
. - AtomicC
Longlong c_longlong
- An atomic
c_longlong
. - AtomicC
Schar c_schar
- An atomic
c_schar
. - AtomicC
Short c_short
- An atomic
c_short
. - AtomicC
Uchar c_uchar
- An atomic
c_uchar
. - AtomicC
Uint c_uint
- An atomic
c_uint
. - AtomicC
Ulong c_ulong
- An atomic
c_ulong
. - AtomicC
Ulonglong c_ulonglong
- An atomic
c_ulonglong
. - AtomicC
Ushort c_ushort
- An atomic
c_ushort
. - Atomic
I8 primitives
- An atomic
i8
. - Atomic
I16 primitives
- An atomic
i16
. - Atomic
I32 primitives
- An atomic
i32
. - Atomic
I64 primitives
- An atomic
i64
. - Atomic
I128 primitives
- An atomic
i128
. - Atomic
Isize primitives
- An atomic
isize
. - Atomic
Ptr primitives
- An atomic
*mut T
. - Atomic
U8 primitives
- An atomic
u8
. - Atomic
U16 primitives
- An atomic
u16
. - Atomic
U32 primitives
- An atomic
u32
. - Atomic
U64 primitives
- An atomic
u64
. - Atomic
U128 primitives
- An atomic
u128
. - Atomic
Usize primitives
- An atomic
usize
.