#atomic #integer #fallback #libc #primitive-integer #c-int

no-std atomic-int

Atomics for additional integers, like C/FFI types

5 releases

0.1.4 Jan 27, 2024
0.1.3 Jan 19, 2024
0.1.2 Sep 28, 2023
0.1.1 Sep 28, 2023
0.1.0 Sep 18, 2023

#70 in No standard library

Download history 1161/week @ 2024-07-20 1529/week @ 2024-07-27 2094/week @ 2024-08-03 956/week @ 2024-08-10 701/week @ 2024-08-17 489/week @ 2024-08-24 723/week @ 2024-08-31 654/week @ 2024-09-07 776/week @ 2024-09-14 682/week @ 2024-09-21 807/week @ 2024-09-28 965/week @ 2024-10-05 1033/week @ 2024-10-12 1425/week @ 2024-10-19 1686/week @ 2024-10-26 782/week @ 2024-11-02

5,019 downloads per month
Used in 2 crates (via filterm)

Apache-2.0

33KB
508 lines

atomic-int

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 platforms[^1] 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.

Dependencies