jaulib v1.3.0
Jau Support Library (C++, Java, ..)
|
Inspired by std::latch of C++20. More...
#include <latch.hpp>
Public Member Functions | |
latch () noexcept | |
Initialize instance with counter zero. More... | |
latch (const latch &o)=delete | |
No copy constructor nor move constructor. More... | |
latch (const size_t count_) noexcept | |
Initialize instance with given counter. More... | |
void | arrive_and_wait (const size_t n=1) noexcept |
Atomically decrements the internal counter by n and (if necessary) blocks the calling thread until the counter reaches zero. More... | |
bool | arrive_and_wait_for (const fraction_i64 &timeout_duration, const size_t n=1) noexcept |
Atomically decrements the internal counter by n and (if necessary) blocks the calling thread until the counter reaches zero or the given timeout duration has expired. More... | |
template<typename Rep , typename Period > | |
bool | arrive_and_wait_for (const std::chrono::duration< Rep, Period > &timeout_duration, const size_t n=1) noexcept |
Atomically decrements the internal counter by n and (if necessary) blocks the calling thread until the counter reaches zero or the given timeout duration has expired. More... | |
void | count_down (const size_t n=1) noexcept |
Atomically decrements the internal counter by n and notifies all blocked wait() threads if zero is reached. More... | |
void | count_up (const size_t n=1) noexcept |
Atomically increments the internal counter by n, i.e. More... | |
void | set (const size_t n) noexcept |
Atomically set the internal counter by n. More... | |
bool | try_wait () const noexcept |
Returns true only if the internal counter has reached zero. More... | |
size_t | value () const noexcept |
Return the current atomic internal counter. More... | |
void | wait () const noexcept |
Blocks the calling thread until the internal counter reaches 0. More... | |
bool | wait_for (const fraction_i64 &timeout_duration) const noexcept |
Blocks the calling thread until the internal counter reaches 0 or the given timeout duration has expired. More... | |
template<typename Rep , typename Period > | |
bool | wait_for (const std::chrono::duration< Rep, Period > &timeout_duration) const noexcept |
Blocks the calling thread until the internal counter reaches 0 or the given timeout duration has expired. More... | |
Static Public Member Functions | |
static constexpr size_t | max () noexcept |
Returns the maximum value of the internal counter supported by the implementation. More... | |
Inspired by std::latch of C++20.
Adds count_up() as an extension, allowing to dynamically add events to required to complete.
|
inlinenoexcept |
Initialize instance with counter zero.
Useful for member instances in combination with count_up() or with set() before count_down().
Extension of std::latch.
|
inlinenoexcept |
|
delete |
No copy constructor nor move constructor.
Compatible with std::latch.
o |
|
inlinestaticconstexprnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Atomically decrements the internal counter by n and notifies all blocked wait() threads if zero is reached.
If n is greater than the value of the internal counter, the counter is set to zero.
This operation strongly happens-before all calls that are unblocked on this latch.
Compatible with std::latch.
n | the value by which the internal counter is decreased, defaults to 1 |
Definition at line 108 of file latch.hpp.
|
inlinenoexcept |
Atomically increments the internal counter by n, i.e.
adds value to count down.
If internal counter + n is greater than the maximum value of the internal counter, the counter is set to its maximum.
This operation strongly happens-before all calls that are unblocked on this latch.
Extension of std::latch.
n | the value by which the internal counter is increased, defaults to 1 |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Atomically decrements the internal counter by n and (if necessary) blocks the calling thread until the counter reaches zero.
Equivalent to count_down(n); wait();
.
Compatible with std::latch.
n | the value by which the internal counter is decreased, defaults to 1 |
Definition at line 193 of file latch.hpp.
|
inlinenoexcept |
Blocks the calling thread until the internal counter reaches 0 or the given timeout duration has expired.
If the internal counter is zero already, returns immediately.
Implementation uses wait_for() w/ a monotonic clock and fraction_i64.
Extension of std::latch.
timeout_duration | maximum duration in fractions of seconds to wait |
Definition at line 210 of file latch.hpp.
|
inlinenoexcept |
Atomically decrements the internal counter by n and (if necessary) blocks the calling thread until the counter reaches zero or the given timeout duration has expired.
Equivalent to count_down(n); wait(timeout_duration);
.
Implementation uses std::chrono::steady_clock::now()
and fraction_i64.
Extension of std::latch.
timeout_duration | maximum duration in fractions of seconds to wait |
n | the value by which the internal counter is decreased, defaults to 1 |
Definition at line 241 of file latch.hpp.
|
inlinenoexcept |
Blocks the calling thread until the internal counter reaches 0 or the given timeout duration has expired.
If the internal counter is zero already, returns immediately.
Implementation uses std::chrono::steady_clock::now()
.
Extension of std::latch.
Rep | |
Period |
timeout_duration | maximum duration to wait |
|
inlinenoexcept |
Atomically decrements the internal counter by n and (if necessary) blocks the calling thread until the counter reaches zero or the given timeout duration has expired.
Equivalent to count_down(n); wait(timeout_duration);
.
Implementation uses std::chrono::steady_clock::now()
.
Extension of std::latch.
Rep | |
Period |
timeout_duration | maximum duration to wait |
n | the value by which the internal counter is decreased, defaults to 1 |