#x86-64 #atomic #pointers #version #compare #exchange #stamped

nightly atomic-stamped-ptr

AtomicStampedPtr for x86_64

2 releases

Uses old Rust 2015

0.1.1 Sep 6, 2016
0.1.0 Aug 21, 2016

#76 in #exchange

23 downloads per month
Used in concurrent-stack

MIT license

10KB
178 lines

AtomicPtr with stamp to avoid ABA problem

Usage

Put this in your Cargo.toml:

[dependencies]
atomic-stamped-ptr = "0.1.0"

And this in your crate root:

extern crate atomic_stamped_ptr;

Getting Started

Store pointer into AtomicStampedPtr atomicity:

let a = AtomicStampedPtr::new(ptr);

Or

a.store(ptr);

Get pointer and version from AtomicStampedPtr atomicity:

let (ptr, version) = a.load();

Swap pointer with AtomicStampedPtr atomicity:

let new_ptr = a.swap(ptr);

Compare and swap:

let (p, v) = a.compare_and_swap((ptr, version), new_ptr);
if (p, v) == (ptr, version) {
    // Success
} else {
    // Failure
}

Comapre and exchange:

if let Ok((p, v)) == a.compare_exchange((ptr, version), new_ptr) {
    // Success
} else {
    // Failure
}

lib.rs:

AtomicStampedPtr

No runtime deps