cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::container::detail Namespace Reference

Classes

class  HazardPointerGuard
 危险指针设置/清除的RAII助手类 (RAII helper for setting/clearing hazard pointers) More...
 
struct  HPRec
 危险指针记录结构体 (Hazard Pointer Record structure) More...
 

Functions

HPRecacquire_hp_record ()
 
void release_hp_record (HPRec *rec)
 释放危险指针记录 (Release a hazard pointer record)
 
void set_hazard_pointer (size_t index, void *ptr)
 为当前线程设置一个危险指针 (Set a hazard pointer for the current thread)
 
void clear_hazard_pointer (size_t index)
 清除当前线程的一个危险指针 (Clear a hazard pointer for the current thread)
 
void scan_retired_nodes ()
 扫描已退休节点并删除安全的节点 (Scan retired nodes and delete safe ones)
 
void retire_node (void *node, std::function< void(void *)> deleter)
 退休一个节点(添加到线程本地列表,偶尔触发扫描) (Retire a node - add to thread-local list, trigger scan occasionally)
 
void cleanup_retired_nodes ()
 清理当前线程的所有剩余退休节点 (Clean up all remaining retired nodes for the current thread)
 

Variables

std::vector< HPRec * > g_hp_list
 
std::mutex g_hp_list_mutex
 
thread_local std::vector< std::pair< void *, std::function< void(void *)> > > t_retired_list
 
constexpr size_t MAX_HAZARD_POINTERS_PER_THREAD = 2
 
constexpr size_t RETIRE_SCAN_THRESHOLD = 100
 

Function Documentation

◆ acquire_hp_record()

HPRec * toolbox::container::detail::acquire_hp_record ( )
inline

◆ cleanup_retired_nodes()

void toolbox::container::detail::cleanup_retired_nodes ( )
inline

清理当前线程的所有剩余退休节点 (Clean up all remaining retired nodes for the current thread)

在线程退出时调用。理想情况下,剩余节点由全局处理或传递给另一个线程。 (Called at thread exit. Ideally, remaining nodes are handled globally or passed to another thread.)

Examples
/home/runner/work/cpp-toolbox/cpp-toolbox/src/include/cpp-toolbox/container/lock_free_queue.hpp.

◆ clear_hazard_pointer()

void toolbox::container::detail::clear_hazard_pointer ( size_t  index)
inline

清除当前线程的一个危险指针 (Clear a hazard pointer for the current thread)

Parameters
index要清除的危险指针索引 (Index of the hazard pointer to clear)
Examples
/home/runner/work/cpp-toolbox/cpp-toolbox/src/include/cpp-toolbox/container/lock_free_queue.hpp.

◆ release_hp_record()

void toolbox::container::detail::release_hp_record ( HPRec rec)
inline

释放危险指针记录 (Release a hazard pointer record)

理想情况下在线程退出队列操作时调用。警告:这是简单实现,对线程退出检测不够健壮。 (Called ideally when thread exits involvement with queue. WARNING: Simple implementation, not robust for thread exit detection.)

Parameters
rec要释放的危险指针记录 (The hazard pointer record to release)
Examples
/home/runner/work/cpp-toolbox/cpp-toolbox/src/include/cpp-toolbox/container/lock_free_queue.hpp.

◆ retire_node()

void toolbox::container::detail::retire_node ( void *  node,
std::function< void(void *)>  deleter 
)
inline

退休一个节点(添加到线程本地列表,偶尔触发扫描) (Retire a node - add to thread-local list, trigger scan occasionally)

Parameters
node要退休的节点指针 (Pointer to the node to retire)
deleter用于删除节点的函数 (Function to delete the node)
Examples
/home/runner/work/cpp-toolbox/cpp-toolbox/src/include/cpp-toolbox/container/lock_free_queue.hpp.

◆ scan_retired_nodes()

void toolbox::container::detail::scan_retired_nodes ( )
inline

扫描已退休节点并删除安全的节点 (Scan retired nodes and delete safe ones)

Examples
/home/runner/work/cpp-toolbox/cpp-toolbox/src/include/cpp-toolbox/container/lock_free_queue.hpp.

◆ set_hazard_pointer()

void toolbox::container::detail::set_hazard_pointer ( size_t  index,
void *  ptr 
)
inline

为当前线程设置一个危险指针 (Set a hazard pointer for the current thread)

Parameters
index危险指针的索引 (Index of the hazard pointer)
ptr要保护的指针 (Pointer to protect)
Examples
/home/runner/work/cpp-toolbox/cpp-toolbox/src/include/cpp-toolbox/container/lock_free_queue.hpp.

Variable Documentation

◆ g_hp_list

std::vector<HPRec*> toolbox::container::detail::g_hp_list
inline

◆ g_hp_list_mutex

std::mutex toolbox::container::detail::g_hp_list_mutex
inline

◆ MAX_HAZARD_POINTERS_PER_THREAD

constexpr size_t toolbox::container::detail::MAX_HAZARD_POINTERS_PER_THREAD = 2
constexpr

◆ RETIRE_SCAN_THRESHOLD

constexpr size_t toolbox::container::detail::RETIRE_SCAN_THRESHOLD = 100
constexpr

◆ t_retired_list

thread_local std::vector<std::pair<void*, std::function<void(void*)> > > toolbox::container::detail::t_retired_list
inline