|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Global Hazard Pointer Domain Manager. More...
#include <safe_hazard_pointer.h>

Public Types | |
| using | retire_callback = std::function<void(void*)> |
Public Member Functions | |
| safe_hazard_pointer_record * | acquire () |
| Acquire a hazard pointer record for current thread. | |
| void | release (safe_hazard_pointer_record *record) noexcept |
| Release a hazard pointer record. | |
| void | retire (void *p, retire_callback deleter) |
| Retire a pointer for later reclamation. | |
| void | collect () |
| Collect reclaimable objects. | |
| size_t | retired_count () const noexcept |
| Get current retired count. | |
| size_t | active_count () const noexcept |
| Get active thread count. | |
Static Public Member Functions | |
| static safe_hazard_pointer_domain & | instance () |
| Get singleton instance. | |
Private Member Functions | |
| safe_hazard_pointer_domain ()=default | |
| ~safe_hazard_pointer_domain () | |
| safe_hazard_pointer_domain (const safe_hazard_pointer_domain &)=delete | |
| safe_hazard_pointer_domain & | operator= (const safe_hazard_pointer_domain &)=delete |
| void | collect_internal () |
| Collect reclaimable objects (internal, lock held) | |
| size_t | get_adaptive_threshold () const noexcept |
| Get adaptive threshold based on active thread count. | |
Private Attributes | |
| std::atomic< safe_hazard_pointer_record * > | head_ {nullptr} |
| std::atomic< size_t > | active_count_ {0} |
| std::atomic< size_t > | retired_count_ {0} |
| std::mutex | retire_mutex_ |
| std::vector< std::pair< void *, retire_callback > > | retired_list_ |
Global Hazard Pointer Domain Manager.
Manages all thread-local hazard pointer records centrally. Provides safe memory reclamation with explicit memory ordering guarantees.
Thread-safe and lock-free for acquire/release operations.
Definition at line 114 of file safe_hazard_pointer.h.
| using kcenon::thread::safe_hazard_pointer_domain::retire_callback = std::function<void(void*)> |
Definition at line 116 of file safe_hazard_pointer.h.
|
privatedefault |
|
inlineprivate |
Definition at line 257 of file safe_hazard_pointer.h.
References head_, and retired_list_.
|
privatedelete |
|
inline |
Acquire a hazard pointer record for current thread.
Lock-free acquisition with proper memory ordering.
Definition at line 132 of file safe_hazard_pointer.h.
References kcenon::thread::safe_hazard_pointer_record::active, active_count_, kcenon::thread::safe_hazard_pointer_record::clear(), head_, and kcenon::thread::safe_hazard_pointer_record::next.

|
inlinenodiscardnoexcept |
Get active thread count.
Definition at line 250 of file safe_hazard_pointer.h.
References active_count_.
|
inline |
Collect reclaimable objects.
Scans all hazard pointers and deletes objects that are not protected.
Definition at line 235 of file safe_hazard_pointer.h.
References collect_internal(), and retire_mutex_.
Referenced by kcenon::thread::typed_safe_hazard_domain< T >::collect(), and retire().


|
inlineprivate |
Collect reclaimable objects (internal, lock held)
Definition at line 281 of file safe_hazard_pointer.h.
References active_count_, kcenon::thread::safe_hazard_pointer_record::get(), head_, kcenon::thread::safe_hazard_pointer_record::MAX_HAZARD_POINTERS, kcenon::thread::safe_hazard_pointer_record::next, retired_count_, and retired_list_.
Referenced by collect().


|
inlinenodiscardprivatenoexcept |
Get adaptive threshold based on active thread count.
Definition at line 329 of file safe_hazard_pointer.h.
References kcenon::thread::active, and active_count_.
Referenced by retire().

|
inlinestatic |
Get singleton instance.
Definition at line 121 of file safe_hazard_pointer.h.
Referenced by kcenon::thread::typed_safe_hazard_domain< T >::collect(), kcenon::thread::safe_hazard_guard::operator=(), kcenon::thread::detail::lockfree_job_queue::retire_node(), kcenon::thread::safe_retire_hazard(), and kcenon::thread::safe_hazard_guard::~safe_hazard_guard().

|
privatedelete |
|
inlinenoexcept |
Release a hazard pointer record.
| record | Record to release |
Clears all hazard pointers and marks record as inactive.
Definition at line 175 of file safe_hazard_pointer.h.
References active_count_.
Referenced by kcenon::thread::safe_hazard_guard::operator=(), and kcenon::thread::safe_hazard_guard::~safe_hazard_guard().

|
inline |
Retire a pointer for later reclamation.
| p | Pointer to retire |
| deleter | Deletion callback |
Thread-safe. Triggers collection when threshold is reached. Handles duplicate addresses by removing old entries (memory reuse scenario).
Definition at line 194 of file safe_hazard_pointer.h.
References collect(), get_adaptive_threshold(), retire_mutex_, retired_count_, and retired_list_.
Referenced by kcenon::thread::detail::lockfree_job_queue::retire_node(), and kcenon::thread::safe_retire_hazard().


|
inlinenodiscardnoexcept |
Get current retired count.
Definition at line 243 of file safe_hazard_pointer.h.
References retired_count_.
|
private |
Definition at line 339 of file safe_hazard_pointer.h.
Referenced by acquire(), active_count(), collect_internal(), get_adaptive_threshold(), and release().
|
private |
Definition at line 338 of file safe_hazard_pointer.h.
Referenced by acquire(), collect_internal(), and ~safe_hazard_pointer_domain().
|
private |
Definition at line 341 of file safe_hazard_pointer.h.
|
private |
Definition at line 340 of file safe_hazard_pointer.h.
Referenced by collect_internal(), retire(), and retired_count().
|
private |
Definition at line 342 of file safe_hazard_pointer.h.
Referenced by collect_internal(), retire(), and ~safe_hazard_pointer_domain().