pub struct Agc<T: Trace + 'static> { /* private fields */ }
sync
only.Expand description
A cycle-collected reference-counted smart pointer which may be shared across threads and supports concurrent collection.
Agc<T>
provides shared ownership of a value of type T
, allocated on the heap. Cloning it
will produce a new Agc
instance which points to the same allocation as the original Agc
.
Unlike std::sync::Arc
, Agc
pointers may refer to each other in a way that creates cycles
arbitrarily without causing leaks, provided that the program calls collect
to collect those
cycles.
- In most cases you must call collect to reclaim memory for dropped
Agc
s even if they are acyclical. - You may call
collect
from any thread to collect cycles. The implementation of collect is intended to provide very low pause times for concurrently running threads, although it will block the thread which actually invokescollect
until the collection is complete.- While the exact details are subject to change, the current implementation will block
access to
Agc
s data for as long as it takes to update its metadata, and will only do so if thatAgc
is a candidate for collection.
- While the exact details are subject to change, the current implementation will block
access to
Implementations§
Source§impl<T> Agc<T>where
T: Trace + 'static,
impl<T> Agc<T>where
T: Trace + 'static,
Sourcepub fn strong_count(this: &Self) -> usize
pub fn strong_count(this: &Self) -> usize
Retrieve the current number of strong references outstanding.
Sourcepub fn read(&self) -> Ref<'_, T>
pub fn read(&self) -> Ref<'_, T>
Blocks the thread until it can acquire a non-exclusive reference into this Agc
.
The returned object is an RAII guard which releases a shared lock. Multiple references may be taken out at the same time.
§Deadlocks
May deadlock if the value is Dead
. This should not occur under normal circumstances and
likely indicates a bug in a Trace
implementation.
§Panics
Panics if the value is Dead
. This should not occur under normal circumstances and likely
indicates a bug in a Trace
implementation.
Sourcepub fn try_borrow(&self) -> Option<Ref<'_, T>>
pub fn try_borrow(&self) -> Option<Ref<'_, T>>
Try to get a non-exclusive reference into this Agc
. This will not block the calling
thread. This may fail if the object is being concurrently traced by the collector.
Returns None if the pointer is dead or exclusively referenced.
Trait Implementations§
Source§impl<T> Ord for Agc<T>
impl<T> Ord for Agc<T>
Source§impl<T> PartialOrd for Agc<T>where
T: PartialOrd + Trace + 'static,
impl<T> PartialOrd for Agc<T>where
T: PartialOrd + Trace + 'static,
Source§impl<T> Trace for Agc<T>where
T: Trace + 'static,
impl<T> Trace for Agc<T>where
T: Trace + 'static,
Source§fn visit_children(&self, visitor: &mut GcVisitor<'_>)
fn visit_children(&self, visitor: &mut GcVisitor<'_>)
visit_children
on each
owned value which implements Trace
.impl<T> Eq for Agc<T>
Auto Trait Implementations§
impl<T> Freeze for Agc<T>
impl<T> !RefUnwindSafe for Agc<T>
impl<T> Send for Agc<T>
impl<T> Sync for Agc<T>
impl<T> Unpin for Agc<T>
impl<T> !UnwindSafe for Agc<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.