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<const COLLECTION_THRESHOLD: u8> Domain<COLLECTION_THRESHOLD>
impl<const COLLECTION_THRESHOLD: u8> Domain<COLLECTION_THRESHOLD>
Sourcepub const fn with_threshold() -> Self
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.
Sourcepub fn protect<T>(&self, ptr: &AtomicPtr<T>) -> Option<Guard<'_, T>>
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.
Sourcepub unsafe fn protect_ptr<T>(&self, ptr: *mut T) -> Option<Guard<'_, T>>
pub unsafe fn protect_ptr<T>(&self, ptr: *mut T) -> Option<Guard<'_, T>>
Sourcepub unsafe fn retire_ptr<T>(&self, ptr: *mut T)
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.