pub struct HazardPointerArray<'domain, F, const N: usize> { /* private fields */ }
Expand description

An efficient way to obtain and hold N HazardPointers.

Construct one either with

let _: HazardPointerArray<haphazard::Global, 4> = HazardPointerArray::default();

or using HazardPointer::many/HazardPointer::many_in_domain:

let _ = HazardPointer::many::<4>();
let _ = HazardPointer::many_in_domain::<4>(haphazard::Domain::global());

To use the individual hazard pointers, use HazardPointerArray::as_refs, or protect multiple AtomicPtrs using HazardPointerArray::protect_all.

Implementations§

source§

impl<'domain, F, const N: usize> HazardPointerArray<'domain, F, N>

source

pub fn as_refs<'array>( &'array mut self ) -> [&'array mut HazardPointer<'domain, F>; N]

Reference the N allocated HazardPointers.

If you’re curious why you can’t just slice directly into HazardPointerArray, it’s because doing so would mutable borrow the entire array, which would make the other pointers unusable. The borrow checker knows that individual elements in a [_; N] are distinct, and can be borrowed individually, but does not know that that is the case for SomeType[i].

source

pub unsafe fn protect_all<'l, T>( &'l mut self, sources: [&AtomicPtr<T>; N] ) -> [Option<&'l T>; N]
where T: Sync, F: 'static,

Protect the value loaded from each AtomicPtr, and dereference each one to &T.

The order of the returned references matches the order of sources.

This operation will load each AtomicPtr multiple times:

  1. load to get the currently stored pointer, ptr
  2. store ptr into the hazard pointer to protect it from reclamation
  3. load again to check that the pointer didn’t change between 1 and 2. if it did, set the loaded value to ptr and goto 2.

Produces None at a given index if the loaded pointer for that AtomicPtr was null.

Safety
  1. The values loaded each AtomicPtr are all valid &T, or null.
  2. The loaded &T will only be deallocated through calls to retire functions on the same Domain as this holder is associated with.
source

pub fn reset_protection(&mut self)

Release the protection awarded by the contained hazard pointers, if any.

If the hazard pointer array was protecting any objects, those objects may now be reclaimed when retired (assuming they aren’t protected by any other hazard pointers).

Trait Implementations§

source§

impl<const N: usize> Default for HazardPointerArray<'static, Global, N>

source§

fn default() -> Self

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

impl<'domain, F, const N: usize> Drop for HazardPointerArray<'domain, F, N>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'domain, F, const N: usize> RefUnwindSafe for HazardPointerArray<'domain, F, N>
where F: RefUnwindSafe,

§

impl<'domain, F, const N: usize> Send for HazardPointerArray<'domain, F, N>
where F: Sync,

§

impl<'domain, F, const N: usize> Sync for HazardPointerArray<'domain, F, N>
where F: Sync,

§

impl<'domain, F, const N: usize> Unpin for HazardPointerArray<'domain, F, N>

§

impl<'domain, F, const N: usize> UnwindSafe for HazardPointerArray<'domain, F, N>
where F: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Reclaim for T