Crate atomic_int
source ·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.
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
.
This crate is no_std
when libc
is not enabled.
As long as the platform supports
AtomicBool
, which is required for the fallback implementation. ↩
Structs§
- An example fallback implementation of an atomic integer.
- An example fallback implementation of an atomic pointer.
Type Aliases§
- AtomicBool
primitives
An atomicbool
. - AtomicCChar
c_char
An atomicc_char
. - AtomicCInt
c_int
An atomicc_int
. - AtomicCLong
c_long
An atomicc_long
. - AtomicCLonglong
c_longlong
An atomicc_longlong
. - AtomicCSchar
c_schar
An atomicc_schar
. - AtomicCShort
c_short
An atomicc_short
. - AtomicCUchar
c_uchar
An atomicc_uchar
. - AtomicCUint
c_uint
An atomicc_uint
. - AtomicCUlong
c_ulong
An atomicc_ulong
. - AtomicCUlonglong
c_ulonglong
An atomicc_ulonglong
. - AtomicCUshort
c_ushort
An atomicc_ushort
. - AtomicI8
primitives
An atomici8
. - AtomicI16
primitives
An atomici16
. - AtomicI32
primitives
An atomici32
. - AtomicI64
primitives
An atomici64
. - AtomicI128
primitives
An atomici128
. - AtomicIsize
primitives
An atomicisize
. - AtomicPtr
primitives
An atomic*mut T
. - AtomicU8
primitives
An atomicu8
. - AtomicU16
primitives
An atomicu16
. - AtomicU32
primitives
An atomicu32
. - AtomicU64
primitives
An atomicu64
. - AtomicU128
primitives
An atomicu128
. - AtomicUsize
primitives
An atomicusize
.