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.


  1. As long as the platform supports AtomicBool, which is required for the fallback implementation. 

Structs§

AtomicFallbackdoc
An example fallback implementation of an atomic integer.
AtomicFallbackPtrdoc
An example fallback implementation of an atomic pointer.

Type Aliases§

AtomicBoolprimitives
An atomic bool.
AtomicCCharc_char
An atomic c_char.
AtomicCIntc_int
An atomic c_int.
AtomicCLongc_long
An atomic c_long.
AtomicCLonglongc_longlong
An atomic c_longlong.
AtomicCScharc_schar
An atomic c_schar.
AtomicCShortc_short
An atomic c_short.
AtomicCUcharc_uchar
An atomic c_uchar.
AtomicCUintc_uint
An atomic c_uint.
AtomicCUlongc_ulong
An atomic c_ulong.
AtomicCUlonglongc_ulonglong
An atomic c_ulonglong.
AtomicCUshortc_ushort
An atomic c_ushort.
AtomicI8primitives
An atomic i8.
AtomicI16primitives
An atomic i16.
AtomicI32primitives
An atomic i32.
AtomicI64primitives
An atomic i64.
AtomicI128primitives
An atomic i128.
AtomicIsizeprimitives
An atomic isize.
AtomicPtrprimitives
An atomic *mut T.
AtomicU8primitives
An atomic u8.
AtomicU16primitives
An atomic u16.
AtomicU32primitives
An atomic u32.
AtomicU64primitives
An atomic u64.
AtomicU128primitives
An atomic u128.
AtomicUsizeprimitives
An atomic usize.