|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Adaptive synchronization policy that can switch modes. More...
#include <sync_policies.h>

Public Types | |
| enum class | mode { mutex , lock_free } |
| Operating mode. More... | |
| using | policy_tag = sync_policy_tag |
Public Member Functions | |
| auto | get_capabilities () const -> queue_capabilities |
| Queue capabilities (dynamic based on mode) | |
| adaptive_sync_policy (mode initial_mode=mode::mutex) | |
| Construct adaptive sync policy. | |
| ~adaptive_sync_policy ()=default | |
| Destructor. | |
| adaptive_sync_policy (const adaptive_sync_policy &)=delete | |
| adaptive_sync_policy & | operator= (const adaptive_sync_policy &)=delete |
| adaptive_sync_policy (adaptive_sync_policy &&)=delete | |
| adaptive_sync_policy & | operator= (adaptive_sync_policy &&)=delete |
| auto | enqueue (std::unique_ptr< job > &&value) -> common::VoidResult |
| Enqueue a job. | |
| auto | dequeue () -> common::Result< std::unique_ptr< job > > |
| Dequeue a job. | |
| auto | try_dequeue () -> common::Result< std::unique_ptr< job > > |
| Try to dequeue a job. | |
| auto | empty () const -> bool |
| Check if queue is empty. | |
| auto | size () const -> std::size_t |
| Get queue size. | |
| auto | clear () -> void |
| Clear queue. | |
| auto | stop () -> void |
| Stop queue. | |
| auto | is_stopped () const -> bool |
| Check if stopped. | |
| auto | set_notify (bool notify) -> void |
| Set notify flag. | |
| auto | current_mode () const -> mode |
| Get current mode. | |
| auto | switch_mode (mode target_mode) -> void |
| Switch to a different mode. | |
Private Attributes | |
| std::atomic< mode > | current_mode_ |
| std::unique_ptr< mutex_sync_policy > | mutex_policy_ |
| std::unique_ptr< lockfree_sync_policy > | lockfree_policy_ |
Adaptive synchronization policy that can switch modes.
Wraps both mutex and lock-free policies and can switch between them based on runtime requirements.
Definition at line 421 of file sync_policies.h.
Definition at line 423 of file sync_policies.h.
|
strong |
Operating mode.
| Enumerator | |
|---|---|
| mutex | Using mutex sync. |
| lock_free | Using lock-free sync. |
Definition at line 428 of file sync_policies.h.
|
inlineexplicit |
Construct adaptive sync policy.
| initial_mode | Initial operating mode |
Definition at line 447 of file sync_policies.h.
|
default |
Destructor.
|
delete |
|
delete |
|
inline |
Clear queue.
Definition at line 522 of file sync_policies.h.
References current_mode_, lockfree_policy_, mutex, and mutex_policy_.
|
inlinenodiscard |
Get current mode.
Definition at line 561 of file sync_policies.h.
References current_mode_.
|
inlinenodiscard |
Dequeue a job.
Definition at line 479 of file sync_policies.h.
References current_mode_, lockfree_policy_, mutex, and mutex_policy_.
|
inlinenodiscard |
Check if queue is empty.
Definition at line 501 of file sync_policies.h.
References current_mode_, lockfree_policy_, mutex, and mutex_policy_.
|
inlinenodiscard |
Enqueue a job.
| value | Job to enqueue |
Definition at line 468 of file sync_policies.h.
References current_mode_, lockfree_policy_, mutex, and mutex_policy_.
|
inlinenodiscard |
Queue capabilities (dynamic based on mode)
Definition at line 436 of file sync_policies.h.
References current_mode_, kcenon::thread::policies::lockfree_sync_policy::get_capabilities(), kcenon::thread::policies::mutex_sync_policy::get_capabilities(), and mutex.

|
inlinenodiscard |
Check if stopped.
Definition at line 542 of file sync_policies.h.
References current_mode_, lockfree_policy_, mutex, and mutex_policy_.
|
delete |
|
delete |
|
inline |
Set notify flag.
| notify | Whether to notify on enqueue |
Definition at line 553 of file sync_policies.h.
References mutex_policy_.
|
inlinenodiscard |
Get queue size.
Definition at line 512 of file sync_policies.h.
References current_mode_, lockfree_policy_, mutex, and mutex_policy_.
|
inline |
Stop queue.
Definition at line 533 of file sync_policies.h.
References lockfree_policy_, and mutex_policy_.
|
inline |
Switch to a different mode.
| target_mode | Target mode to switch to |
Definition at line 571 of file sync_policies.h.
References current_mode_.
|
inlinenodiscard |
Try to dequeue a job.
Definition at line 490 of file sync_policies.h.
References current_mode_, lockfree_policy_, mutex, and mutex_policy_.
|
private |
Definition at line 576 of file sync_policies.h.
Referenced by clear(), current_mode(), dequeue(), empty(), enqueue(), get_capabilities(), is_stopped(), size(), switch_mode(), and try_dequeue().
|
private |
Definition at line 578 of file sync_policies.h.
Referenced by clear(), dequeue(), empty(), enqueue(), is_stopped(), size(), stop(), and try_dequeue().
|
private |
Definition at line 577 of file sync_policies.h.
Referenced by clear(), dequeue(), empty(), enqueue(), is_stopped(), set_notify(), size(), stop(), and try_dequeue().