Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::safe_hazard_guard Class Reference

#include <safe_hazard_pointer.h>

Collaboration diagram for kcenon::thread::safe_hazard_guard:
Collaboration graph

Public Member Functions

 safe_hazard_guard (void *p=nullptr, size_t slot=0)
 Construct guard, optionally protecting a pointer.
 
 ~safe_hazard_guard ()
 Destructor - releases the record.
 
 safe_hazard_guard (const safe_hazard_guard &)=delete
 
safe_hazard_guardoperator= (const safe_hazard_guard &)=delete
 
 safe_hazard_guard (safe_hazard_guard &&other) noexcept
 
safe_hazard_guardoperator= (safe_hazard_guard &&other) noexcept
 
void protect (void *p) noexcept
 Protect a pointer.
 
void clear () noexcept
 Clear protection.
 
void * get () const noexcept
 Get protected pointer.
 
 operator bool () const noexcept
 Check if valid.
 

Private Attributes

safe_hazard_pointer_recordrecord_
 
size_t slot_
 

Detailed Description

Definition at line 360 of file safe_hazard_pointer.h.

Constructor & Destructor Documentation

◆ safe_hazard_guard() [1/3]

kcenon::thread::safe_hazard_guard::safe_hazard_guard ( void * p = nullptr,
size_t slot = 0 )
inlineexplicit

Construct guard, optionally protecting a pointer.

Parameters
pPointer to protect (optional)
slotSlot index (0 or 1)
Examples
/home/runner/work/thread_system/thread_system/include/kcenon/thread/core/safe_hazard_pointer.h.

Definition at line 367 of file safe_hazard_pointer.h.

369 , slot_(slot) {
370 if (p != nullptr) {
371 record_->protect(p, slot_);
372 }
373 }
safe_hazard_pointer_record * record_
static safe_hazard_pointer_domain & instance()
Get singleton instance.
void protect(void *p, size_t slot=0) noexcept
Protect a pointer from reclamation.

References kcenon::thread::safe_hazard_pointer_record::protect(), record_, and slot_.

Here is the call graph for this function:

◆ ~safe_hazard_guard()

kcenon::thread::safe_hazard_guard::~safe_hazard_guard ( )
inline

Destructor - releases the record.

Examples
/home/runner/work/thread_system/thread_system/include/kcenon/thread/core/safe_hazard_pointer.h.

Definition at line 378 of file safe_hazard_pointer.h.

378 {
379 if (record_ != nullptr) {
381 }
382 }
void release(safe_hazard_pointer_record *record) noexcept
Release a hazard pointer record.

References kcenon::thread::safe_hazard_pointer_domain::instance(), record_, and kcenon::thread::safe_hazard_pointer_domain::release().

Here is the call graph for this function:

◆ safe_hazard_guard() [2/3]

kcenon::thread::safe_hazard_guard::safe_hazard_guard ( const safe_hazard_guard & )
delete

◆ safe_hazard_guard() [3/3]

kcenon::thread::safe_hazard_guard::safe_hazard_guard ( safe_hazard_guard && other)
inlinenoexcept

Definition at line 389 of file safe_hazard_pointer.h.

390 : record_(other.record_)
391 , slot_(other.slot_) {
392 other.record_ = nullptr;
393 }

Member Function Documentation

◆ clear()

void kcenon::thread::safe_hazard_guard::clear ( )
inlinenoexcept

Clear protection.

Examples
/home/runner/work/thread_system/thread_system/include/kcenon/thread/core/safe_hazard_pointer.h.

Definition at line 420 of file safe_hazard_pointer.h.

420 {
421 if (record_ != nullptr) {
423 }
424 }
void clear(size_t slot=0) noexcept
Clear hazard pointer protection.

References kcenon::thread::safe_hazard_pointer_record::clear(), record_, and slot_.

Here is the call graph for this function:

◆ get()

void * kcenon::thread::safe_hazard_guard::get ( ) const
inlinenodiscardnoexcept

Get protected pointer.

Examples
/home/runner/work/thread_system/thread_system/include/kcenon/thread/core/safe_hazard_pointer.h.

Definition at line 429 of file safe_hazard_pointer.h.

429 {
430 return record_ != nullptr ? record_->get(slot_) : nullptr;
431 }
void * get(size_t slot=0) const noexcept
Get protected pointer at slot.

References kcenon::thread::safe_hazard_pointer_record::get(), record_, and slot_.

Here is the call graph for this function:

◆ operator bool()

kcenon::thread::safe_hazard_guard::operator bool ( ) const
inlineexplicitnodiscardnoexcept

Check if valid.

Definition at line 436 of file safe_hazard_pointer.h.

436 {
437 return record_ != nullptr;
438 }

References record_.

◆ operator=() [1/2]

◆ operator=() [2/2]

safe_hazard_guard & kcenon::thread::safe_hazard_guard::operator= ( safe_hazard_guard && other)
inlinenoexcept

Definition at line 395 of file safe_hazard_pointer.h.

395 {
396 if (this != &other) {
397 if (record_ != nullptr) {
399 }
400 record_ = other.record_;
401 slot_ = other.slot_;
402 other.record_ = nullptr;
403 }
404 return *this;
405 }

References kcenon::thread::safe_hazard_pointer_domain::instance(), record_, kcenon::thread::safe_hazard_pointer_domain::release(), and slot_.

Here is the call graph for this function:

◆ protect()

void kcenon::thread::safe_hazard_guard::protect ( void * p)
inlinenoexcept

Protect a pointer.

Parameters
pPointer to protect
Examples
/home/runner/work/thread_system/thread_system/include/kcenon/thread/core/safe_hazard_pointer.h.

Definition at line 411 of file safe_hazard_pointer.h.

411 {
412 if (record_ != nullptr) {
413 record_->protect(p, slot_);
414 }
415 }

References kcenon::thread::safe_hazard_pointer_record::protect(), record_, and slot_.

Referenced by kcenon::thread::detail::lockfree_job_queue::dequeue(), kcenon::thread::detail::lockfree_job_queue::empty(), and kcenon::thread::detail::lockfree_job_queue::enqueue().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ record_

◆ slot_

size_t kcenon::thread::safe_hazard_guard::slot_
private

The documentation for this class was generated from the following file: