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.


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].

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.

  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.

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

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

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.