1#ifndef HAZARD_POINTER_H
2#define HAZARD_POINTER_H
8#include <unordered_set>
35 ::std::atomic<void *>
slot{
nullptr };
55 class HazardPtrDomain {
141 #include "CNum/DataStructs/Memory/HazardPointer.tpp"
HazardSlot * acquire_hazard_slot()
Acquire ownership of a slot to protect a hazard pointer.
void release_hazard_slot(HazardSlot *slot)
Release ownership of a hazard pointer slot.
static HazardPtrDomain * get_domain()
Get a pointer to the instance of the HazardPtrDomain singleton.
void hazard_slots_gather(::std::vector< void * > &out)
Get all active hazard pointer slots.
HazardPtrGuard()
Default constructor.
HazardPtrGuard(const HazardPtrGuard &)=delete
~HazardPtrGuard()
Destructor.
void clear_slot(size_t idx)
Clear one of the guard's slots.
HazardSlot * get_slot(size_t idx)
Get a pointer to a guard's slot.
void clear_all_slots()
Clear all of the guard's slots.
HazardPtrGuard & operator=(const HazardPtrGuard &)=delete
Tools for protecting "hazerdous" objects in memory.
thread_local ::std::vector< Retire > tls_retire
The thread local storage of retired objects.
Definition HazardPointer.h:49
constexpr size_t RETIRED_SCAN_THRESHOLD
The threshold of Retire objects in the tls_retire at which we call scan().
Definition HazardPointer.h:28
constexpr size_t SLOTS_PER_THREAD
The amount of slots 1 thread can have.
Definition HazardPointer.h:24
void flush()
Force a scan.
void retire(T *ptr)
Retire a pointer.
Definition HazardPointer.h:41
void default_hazard_ptr_delete(void *ptr)
Default delete function for pointers.
Definition HazardPointer.h:5
constexpr size_t MAX_HP_SLOTS
The maximum amount of hazard pointer slots (globally) Add more as needed.
Definition HazardPointer.h:17
T * protect(::std::atomic< T * > &src, HazardSlot *slot)
Protect an atomic pointer.
Definition HazardPointer.h:16
void scan()
Free memory of objects pointed to by pointers that are no longer hazardous.
A slot in which to store a protected pointer.
Definition HazardPointer.h:34
::std::atomic< void * > slot
Definition HazardPointer.h:35
::std::atomic< bool > active
Definition HazardPointer.h:36
A retired protected pointer.
Definition HazardPointer.h:43
void * ptr
Definition HazardPointer.h:44
::std::function< void(void *) > deleter
Definition HazardPointer.h:45