|
CNum 0.2.1
CPU-optimized ML library for C++
|
Tools for protecting "hazerdous" objects in memory. More...
Classes | |
| struct | HazardSlot |
| A slot in which to store a protected pointer. More... | |
| struct | Retire |
| A retired protected pointer. More... | |
| class | HazardPtrDomain |
| The domain of all hazard pointers. More... | |
| class | HazardPtrGuard |
| Thread local guards for hazard pointers. More... | |
Functions | |
| template<typename T> | |
| void | default_hazard_ptr_delete (void *ptr) |
| Default delete function for pointers. | |
| template<typename T> | |
| T * | protect (::std::atomic< T * > &src, HazardSlot *slot) |
| Protect an atomic pointer. | |
| template<typename T> | |
| void | protect (T *src, HazardSlot *slot) |
| Protect a raw pointer. | |
| template<typename T> | |
| void | retire (T *ptr) |
| Retire a pointer. | |
| void | scan () |
| Free memory of objects pointed to by pointers that are no longer hazardous. | |
| void | flush () |
| Force a scan. | |
Variables | |
| constexpr size_t | MAX_HP_SLOTS = 1024 |
| The maximum amount of hazard pointer slots (globally) Add more as needed. | |
| constexpr size_t | SLOTS_PER_THREAD = 2 |
| The amount of slots 1 thread can have. | |
| constexpr size_t | RETIRED_SCAN_THRESHOLD = 64 |
| The threshold of Retire objects in the tls_retire at which we call scan(). | |
| thread_local ::std::vector< Retire > | tls_retire |
| The thread local storage of retired objects. | |
Tools for protecting "hazerdous" objects in memory.
| void CNum::DataStructs::HazardPointer::default_hazard_ptr_delete | ( | void * | ptr | ) |
Default delete function for pointers.
| ptr | The pointer to free |
| void CNum::DataStructs::HazardPointer::flush | ( | ) |
Force a scan.
| T * CNum::DataStructs::HazardPointer::protect | ( | ::std::atomic< T * > & | src, |
| HazardSlot * | slot ) |
Protect an atomic pointer.
Used for ensuring that a pointer shared by multiple threads does not get deleted (freed) when another is actively using it
| src | Atomic pointer to protect |
| slot | The slot in which to store the pointer |
| void CNum::DataStructs::HazardPointer::protect | ( | T * | src, |
| HazardSlot * | slot ) |
Protect a raw pointer.
Used for ensuring that a pointer shared by multiple threads does not get deleted (freed) when another is actively using it
| src | The raw pointer to protect |
| slot | The slot in which to store the pointer |
| void CNum::DataStructs::HazardPointer::retire | ( | T * | ptr | ) |
| void CNum::DataStructs::HazardPointer::scan | ( | ) |
Free memory of objects pointed to by pointers that are no longer hazardous.
Iterate over the tls_retire and check if the pointers are hazardous by checking if it is active in the global domain (i.e. marked hazardous by thread)
|
constexpr |
The maximum amount of hazard pointer slots (globally) Add more as needed.
|
constexpr |
|
constexpr |
The amount of slots 1 thread can have.
I assigned a value of 2 because 2 is all that is required for my lock-free concurrent queue. But for your own implementations of lock-free data structures you may need to increase this value.
|
inline |
The thread local storage of retired objects.