|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Helper class to add wait/notify functionality to std::atomic. More...
#include <atomic_wait.h>

Public Member Functions | |
| void | wait (std::atomic< T > &atomic, T old) noexcept |
| Blocks until the atomic value differs from the expected value. | |
| void | notify_one () noexcept |
| Unblocks one thread waiting on this atomic. | |
| void | notify_all () noexcept |
| Unblocks all threads waiting on this atomic. | |
Private Attributes | |
| std::mutex | mutex_ |
| std::condition_variable | cv_ |
Helper class to add wait/notify functionality to std::atomic.
This class provides atomic waiting primitives similar to C++20's std::atomic::wait/notify. It uses an efficient implementation with:
| T | The atomic value type (must be trivially copyable) |
Usage:
Definition at line 63 of file atomic_wait.h.
|
inlinenoexcept |
Unblocks all threads waiting on this atomic.
All waiting threads will wake up and re-check their condition.
Definition at line 138 of file atomic_wait.h.
References kcenon::thread::atomic_wait_helper< T >::cv_, and kcenon::thread::atomic_wait_helper< T >::mutex_.
|
inlinenoexcept |
Unblocks one thread waiting on this atomic.
If multiple threads are waiting, exactly one will be woken up. Which thread is unspecified (depends on scheduler).
Definition at line 126 of file atomic_wait.h.
References kcenon::thread::atomic_wait_helper< T >::cv_, and kcenon::thread::atomic_wait_helper< T >::mutex_.
|
inlinenoexcept |
Blocks until the atomic value differs from the expected value.
This function implements an efficient wait with:
Memory ordering: Uses acquire semantics to ensure proper synchronization
| atomic | The atomic variable to monitor |
| old | The expected value to wait for change |
Definition at line 81 of file atomic_wait.h.
References kcenon::thread::atomic_wait_helper< T >::cv_, and kcenon::thread::atomic_wait_helper< T >::mutex_.
|
mutableprivate |
Definition at line 145 of file atomic_wait.h.
Referenced by kcenon::thread::atomic_wait_helper< T >::notify_all(), kcenon::thread::atomic_wait_helper< T >::notify_one(), and kcenon::thread::atomic_wait_helper< T >::wait().
|
mutableprivate |
Definition at line 144 of file atomic_wait.h.
Referenced by kcenon::thread::atomic_wait_helper< T >::notify_all(), kcenon::thread::atomic_wait_helper< T >::notify_one(), and kcenon::thread::atomic_wait_helper< T >::wait().