pub struct SwapArcAnyMeta<T: Send + Sync, D: DataPtrConvert<T> = Arc<T>, const METADATA_BITS: u32 = 0> { /* private fields */ }
Expand description
A SwapArc
is a data structure that allows for an Arc
to be passed around and swapped out with other Arc
s.
In order to achieve this, an internal reference count
scheme is used which allows for very quick, low overhead
reads in the common case (no update) and will still be
decently fast when an update is performed. When a new
Arc
is to be stored in the SwapArc
, it first tries to
immediately update the current pointer (the one all strong readers
will see in the uncontended case)
(this is possible, if no other update is being performed and if there are no strong readers
left)
if this fails, it will try to do the same thing with the intermediate
pointer
and if even that fails, it will push
the update so that it will
be performed by the last intermediate
reader to finish reading.
A strong read
consists of loading the current pointer and
performing a clone operation on the Arc
, thus
strong readers
are very short-lived and can’t block
updates for very long.
A strong read
in this case refers to the process of acquiring
the shared pointer which gets handled by the SwapArc
itself internally. Note that such a strong read
isn’t what would
typically happen when load
gets called as such a call
usually (in the case of no update) will only result
in a weak read
and thus only
in a single Relaxed
atomic load and a couple of
non-atomic bookkeeping operations utilizing TLS
to cache previous reads.
Note: SwapArc
has wait-free reads.
Implementations§
Source§impl<T: Send + Sync, D: DataPtrConvert<T>, const METADATA_BITS: u32> SwapArcAnyMeta<T, D, METADATA_BITS>
impl<T: Send + Sync, D: DataPtrConvert<T>, const METADATA_BITS: u32> SwapArcAnyMeta<T, D, METADATA_BITS>
Sourcepub fn load(&self) -> SwapArcGuard<'_, T, D, METADATA_BITS>
pub fn load(&self) -> SwapArcGuard<'_, T, D, METADATA_BITS>
Loads the reference counted stored value partially.
Sourcepub fn load_full(&self) -> D
pub fn load_full(&self) -> D
Loads the reference counted value that’s currently stored
inside the SwapArc strongly i.e it increases the reference
count directly.
This is slower than load
but will allow for the result
to be used even after the SwapArc
was dropped.
Sourcepub fn store(&self, updated: D)
pub fn store(&self, updated: D)
Update the value inside the SwapArc to value passed in updated
.
Sourcepub fn update_metadata(&self, metadata: usize)
pub fn update_metadata(&self, metadata: usize)
Updates the currently stored metadata with the new
metadata passed in the metadata
parameter.
Sourcepub fn set_in_metadata(&self, active_bits: usize)
pub fn set_in_metadata(&self, active_bits: usize)
Sets all bits of the internal pointer which are set in the inactive_bits
parameter
Sourcepub fn unset_in_metadata(&self, inactive_bits: usize)
pub fn unset_in_metadata(&self, inactive_bits: usize)
Unsets all bits of the internal pointer which are set in the inactive_bits
parameter
Sourcepub fn load_metadata(&self) -> usize
pub fn load_metadata(&self) -> usize
Returns the metadata stored inside the internal pointer