#atomic #128-bit-atomics

nightly atomicdouble

128-bit atomics for generic type

1 unstable release

0.1.4 Oct 16, 2021
0.1.3 Sep 6, 2021
0.1.2 Aug 29, 2021
0.1.1 Aug 28, 2021
0.1.0 Aug 28, 2021

#593 in Concurrency

Download history 8/week @ 2023-11-02 5/week @ 2023-11-09 14/week @ 2023-11-16 10/week @ 2023-11-23 24/week @ 2023-11-30 4/week @ 2023-12-07 9/week @ 2023-12-14 13/week @ 2023-12-21 4/week @ 2023-12-28 4/week @ 2024-01-04 5/week @ 2024-01-11 8/week @ 2024-01-18 14/week @ 2024-01-25 11/week @ 2024-02-01 17/week @ 2024-02-08 82/week @ 2024-02-15

124 downloads per month
Used in hyaline-smr

Apache-2.0/MIT

21KB
393 lines

AtomicDouble<T>

A Rust library which provides 128-bit atomic operations for generic types on supported architectures (currently only x86_64 with cmpxchg16b is supported). In cases where atomic operations can't be supported fallback implementation using spin-locks has been provided.

You can use the AtomicDouble::<T>::is_lock_free() function to check whether native atomic operations are supported for a given type. Note that the library is tailor made for 128-bit operations, types violating the size constraints will use the fallback implementation. Fallback implementation is enabled by default and can be disabled by adding default-features = false to the dependency declaration.

This crate requires nightly.

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
atomicdouble = "0.1.4"

Example

use std::ptr::NonNull;

use atomicdouble::AtomicDouble;
use atomicdouble::Ordering::SeqCst;

#[derive(Copy, Clone, Eq, PartialEq, Debug,Default)]
struct Node {
    head_ptr : Option< NonNull<i32> >,
    head_count : usize //assuming 64-bit machine
}

fn main() {
    let x = Box::new(5);
    let temp_node_x = Node {
        head_ptr:NonNull::new(Box::into_raw(x)),
        head_count:3
    };
    let a:AtomicDouble::<Node> = AtomicDouble::new(temp_node_x);
    println!("{}",AtomicDouble::<Node>::is_lock_free());
    let load_test = a.load(SeqCst);
    unsafe {
        let load_test_x = Box::from_raw(load_test.head_ptr.unwrap().as_ptr());
        println!("{}",*load_test_x);
        println!("{}",load_test.head_count);
    };
}

License

Licensed under either of

at your option.

Contribution

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.

Credits

This crate is effectively a 128-bit only version of Atomic<T> crate. Atomic<T> crate doesn't work for 128 bit atomics for now, as rust doesnt have support for AtomicU128/AtomicI128 yet. In the mean time AtomicDouble can be used as a replacement.

No runtime deps

Features