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
sourceimpl<T: 'static> AtomicArc<T>
impl<T: 'static> AtomicArc<T>
sourcepub fn swap(
&self,
new: (Option<Arc<T>>, Tag),
order: Ordering
) -> Option<Arc<T>>
pub fn swap(
&self,
new: (Option<Arc<T>>, Tag),
order: Ordering
) -> Option<Arc<T>>
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());
sourcepub fn update_tag_if<F: FnMut(Tag) -> bool>(
&self,
tag: Tag,
condition: F,
order: Ordering
) -> bool
pub fn update_tag_if<F: FnMut(Tag) -> bool>(
&self,
tag: Tag,
condition: F,
order: Ordering
) -> bool
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);
sourcepub fn compare_exchange<'b>(
&self,
current: Ptr<'b, T>,
new: (Option<Arc<T>>, Tag),
success: Ordering,
failure: Ordering
) -> Result<(Option<Arc<T>>, Ptr<'b, T>), (Option<Arc<T>>, Ptr<'b, T>)>
pub fn compare_exchange<'b>(
&self,
current: Ptr<'b, T>,
new: (Option<Arc<T>>, Tag),
success: Ordering,
failure: Ordering
) -> Result<(Option<Arc<T>>, Ptr<'b, T>), (Option<Arc<T>>, Ptr<'b, T>)>
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);
sourcepub fn clone(&self, order: Ordering, _barrier: &Barrier) -> AtomicArc<T>
pub fn clone(&self, order: Ordering, _barrier: &Barrier) -> AtomicArc<T>
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);
sourcepub fn get_arc(&self, order: Ordering, _barrier: &Barrier) -> Option<Arc<T>>
pub fn get_arc(&self, order: Ordering, _barrier: &Barrier) -> Option<Arc<T>>
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);
sourcepub fn try_into_arc(self, order: Ordering) -> Option<Arc<T>>
pub fn try_into_arc(self, order: Ordering) -> Option<Arc<T>>
Trait Implementations
impl<T: 'static> Send for AtomicArc<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for AtomicArc<T>
impl<T> Sync for AtomicArc<T>
impl<T> Unpin for AtomicArc<T>
impl<T> !UnwindSafe for AtomicArc<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more