Skip to main content

Domain

Struct Domain 

Source
pub struct Domain<const COLLECTION_THRESHOLD: u8 = DEFAULT_COLLECTION_THRESHOLD> { /* private fields */ }
Expand description

A hazard pointer domain that manages hazard slots and deferred reclamation.

All pointers protected and retired through the same domain share a single hazard list. Retired pointers are stored in a lock-free Treiber stack and reclaimed when no hazard slot references them.

Typically one global domain is sufficient:

use lockout_hazard::Domain;
static DOMAIN: Domain = Domain::new();

Implementations§

Source§

impl Domain

Source

pub const fn new() -> Self

Creates a new hazard pointer domain.

This is a const fn, so it can be used in static declarations.

Source§

impl<const COLLECTION_THRESHOLD: u8> Domain<COLLECTION_THRESHOLD>

Source

pub const fn with_threshold() -> Self

Creates a new hazard pointer domain with a threshold for automatic pointer reclamation specified as a generic parameter.

This is a const fn, so it can be used in static declarations.

Source

pub fn protect<T>(&self, ptr: &AtomicPtr<T>) -> Option<Guard<'_, T>>

Protects the pointer stored in a AtomicPtr by publishing it in a hazard slot.

Uses a load-reserve-verify loop to ensure the returned guard protects the value that was in ptr at the time of the call. Returns None if the pointer is null.

Source

pub unsafe fn protect_ptr<T>(&self, ptr: *mut T) -> Option<Guard<'_, T>>

Protects an arbitrary raw pointer by publishing it in a hazard slot.

Unlike protect, this does not verify the pointer against an AtomicPtr source. The caller must ensure the pointer is valid. Returns None if the pointer is null.

§Safety

The pointer must point to a valid, live allocation.

Source

pub unsafe fn retire_ptr<T>(&self, ptr: *mut T)

Retires a raw pointer, scheduling it for deferred reclamation.

The pointer will be deallocated (via Box::from_raw) once no hazard slot references it.

§Safety
  • The pointer must have been allocated with Box.
  • The pointer must no longer be reachable from any shared atomic.
  • The pointer must not be retired more than once.
Source

pub fn collect(&self)

Scans all hazard slots and reclaims any retired pointers that are not currently protected.

This is called automatically every [COLLECTION_THRESHOLD] retires, but can also be called manually to force reclamation. Resets the retire counter.

Trait Implementations§

Source§

impl<const COLLECTION_THRESHOLD: u8> Debug for Domain<COLLECTION_THRESHOLD>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Domain<DEFAULT_COLLECTION_THRESHOLD>

Source§

fn default() -> Self

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

impl<const COLLECTION_THRESHOLD: u8> Drop for Domain<COLLECTION_THRESHOLD>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Domain

Source§

impl Sync for Domain

Auto Trait Implementations§

§

impl<const COLLECTION_THRESHOLD: u8 = DEFAULT_COLLECTION_THRESHOLD> !Freeze for Domain<COLLECTION_THRESHOLD>

§

impl<const COLLECTION_THRESHOLD: u8> RefUnwindSafe for Domain<COLLECTION_THRESHOLD>

§

impl<const COLLECTION_THRESHOLD: u8 = DEFAULT_COLLECTION_THRESHOLD> !Send for Domain<COLLECTION_THRESHOLD>

§

impl<const COLLECTION_THRESHOLD: u8 = DEFAULT_COLLECTION_THRESHOLD> !Sync for Domain<COLLECTION_THRESHOLD>

§

impl<const COLLECTION_THRESHOLD: u8> Unpin for Domain<COLLECTION_THRESHOLD>

§

impl<const COLLECTION_THRESHOLD: u8> UnsafeUnpin for Domain<COLLECTION_THRESHOLD>

§

impl<const COLLECTION_THRESHOLD: u8> UnwindSafe for Domain<COLLECTION_THRESHOLD>

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>,

Source§

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>,

Source§

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.