pub struct AtomicArc<T: 'static> { /* private fields */ }
Expand description

AtomicArc owns the underlying instance, and allows users to perform atomic operations on the pointer to it.

Implementations

Creates a new AtomicArc from an instance of T.

Examples
use scc::ebr::AtomicArc;

let atomic_arc: AtomicArc<usize> = AtomicArc::new(10);

Creates a new AtomicArc from an Arc of T.

Examples
use scc::ebr::{Arc, AtomicArc};

let arc: Arc<usize> = Arc::new(10);
let atomic_arc: AtomicArc<usize> = AtomicArc::from(arc);

Creates a null AtomicArc.

Examples
use scc::ebr::AtomicArc;

let atomic_arc: AtomicArc<usize> = AtomicArc::null();

Returns true if the AtomicArc is null.

Examples
use scc::ebr::{AtomicArc, Tag};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::null();
atomic_arc.update_tag_if(Tag::Both, |t| t == Tag::None, Relaxed);
assert!(atomic_arc.is_null(Relaxed));

Loads a pointer value from the AtomicArc.

Examples
use scc::ebr::{AtomicArc, Barrier};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::new(11);
let barrier = Barrier::new();
let ptr = atomic_arc.load(Relaxed, &barrier);
assert_eq!(*ptr.as_ref().unwrap(), 11);

Stores the given value into the AtomicArc and returns the original value.

Examples
use scc::ebr::{Arc, AtomicArc, Barrier, Tag};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::new(14);
let barrier = Barrier::new();
let old = atomic_arc.swap((Some(Arc::new(15)), Tag::Second), Relaxed);
assert_eq!(*old.unwrap(), 14);
let old = atomic_arc.swap((None, Tag::First), Relaxed);
assert_eq!(*old.unwrap(), 15);
let old = atomic_arc.swap((None, Tag::None), Relaxed);
assert!(old.is_none());

Returns its Tag.

Examples
use scc::ebr::{AtomicArc, Tag};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::null();
assert_eq!(atomic_arc.tag(Relaxed), Tag::None);

Sets a new Tag if the given condition is met.

It returns true if the condition is met.

Examples
use scc::ebr::{AtomicArc, Tag};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::null();
assert!(atomic_arc.update_tag_if(Tag::Both, |t| t == Tag::None, Relaxed));
assert_eq!(atomic_arc.tag(Relaxed), Tag::Both);

Performs CAS on the AtomicArc.

It returns Ok with the previously held Arc and the updated Ptr upon a successful operation.

Errors

It returns Err with the supplied Arc and the current Ptr.

Examples
use scc::ebr::{Arc, AtomicArc, Barrier, Tag};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::new(17);
let barrier = Barrier::new();

let mut ptr = atomic_arc.load(Relaxed, &barrier);
assert_eq!(*ptr.as_ref().unwrap(), 17);

atomic_arc.update_tag_if(Tag::Both, |_| true, Relaxed);
assert!(atomic_arc.compare_exchange(
    ptr, (Some(Arc::new(18)), Tag::First), Relaxed, Relaxed).is_err());

ptr.set_tag(Tag::Both);
let old: Arc<usize> = atomic_arc.compare_exchange(
    ptr, (Some(Arc::new(18)), Tag::First), Relaxed, Relaxed).unwrap().0.unwrap();
assert_eq!(*old, 17);
drop(old);

assert!(atomic_arc.compare_exchange(
    ptr, (Some(Arc::new(19)), Tag::None), Relaxed, Relaxed).is_err());
assert_eq!(*ptr.as_ref().unwrap(), 17);

Clones self including tags.

Examples
use scc::ebr::{Arc, AtomicArc, Barrier};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::new(59);
let barrier = Barrier::new();
let atomic_arc_cloned = atomic_arc.clone(Relaxed, &barrier);
let ptr = atomic_arc_cloned.load(Relaxed, &barrier);
assert_eq!(*ptr.as_ref().unwrap(), 59);

Tries to create an Arc out of self.

Examples
use scc::ebr::{Arc, AtomicArc, Barrier};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::new(47);
let barrier = Barrier::new();
let arc: Arc<usize> = atomic_arc.get_arc(Relaxed, &barrier).unwrap();
assert_eq!(*arc, 47);

Tries to convert self into an Arc.

Examples
use scc::ebr::{Arc, AtomicArc};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::new(55);
let arc: Arc<usize> = atomic_arc.try_into_arc(Relaxed).unwrap();
assert_eq!(*arc, 55);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.