pub struct AtomicArc<T: 'static> { /* private fields */ }Expand description
An Arc with an atomically updatable pointer.
Usage notes:
- An
AtomicArccan intrinsically storeNone(a hypotheticalOption<AtomicArc<T>>would no longer be atomic). - An
AtomicArccontributes to the strong count of the pointed-to allocation, if any. However, it does not implementDeref, so methods likeloadmust be used to obtain aGuardthrough which the data can be accessed. Tmust beSized. This may be relaxed in the future.- When an
AtomicArcis updated or dropped, the strong count of the previously pointed-to object may not be immediately decremented. Thus:Tmust be'staticto support delayed deallocations.- The value returned by
ref_countmay be an overestimate.
§Examples
use aarc::{Arc, AtomicArc, Guard};
// ref count: 1
let x = Arc::new(53);
assert_eq!(Arc::ref_count(&x), 1);
// ref count: 2
let atomic = AtomicArc::new(0);
atomic.store(Some(&x));
assert_eq!(Arc::ref_count(&x), 2);
// guard doesn't affect the ref count
let guard = atomic.load().unwrap();
assert_eq!(Arc::ref_count(&x), 2);
// both the `Arc` and the `Guard` point to the same block
assert_eq!(*guard, 53);
assert_eq!(*guard, *x);Implementations§
Source§impl<T: 'static> AtomicArc<T>
impl<T: 'static> AtomicArc<T>
Sourcepub fn new<D: Into<Option<T>>>(data: D) -> Self
pub fn new<D: Into<Option<T>>>(data: D) -> Self
Similar to Arc::new, but None is a valid input, in which case the AtomicArc will
store a null pointer.
To create an AtomicArc from an existing Arc, use from.
Sourcepub fn load(&self) -> Option<Guard<'static, T>>
pub fn load(&self) -> Option<Guard<'static, T>>
Loads a Guard, which allows the pointed-to value to be accessed. None indicates that
the inner atomic pointer is null.
Trait Implementations§
Source§impl<T: 'static> CompareExchange<T, &Arc<T>> for AtomicArc<T>
impl<T: 'static> CompareExchange<T, &Arc<T>> for AtomicArc<T>
Source§impl<T: 'static> CompareExchange<T, &Guard<'static, T>> for AtomicArc<T>
impl<T: 'static> CompareExchange<T, &Guard<'static, T>> for AtomicArc<T>
impl<T: 'static + Send + Sync> Send for AtomicArc<T>
impl<T: 'static + Send + Sync> Sync for AtomicArc<T>
Auto Trait Implementations§
impl<T> !Freeze for AtomicArc<T>
impl<T> RefUnwindSafe for AtomicArc<T>where
T: RefUnwindSafe,
impl<T> Unpin for AtomicArc<T>where
T: Unpin,
impl<T> UnwindSafe for AtomicArc<T>where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more