Latch synchronization primitive.
More...
#include <latch.h>
Latch synchronization primitive.
Latches are a thread co-ordination mechanism that allow one or more threads to block until one or more threads have reached a point.
Thread-safe.
- Examples
- threads_latch_multi.cpp, and threads_latch_single.cpp.
Definition at line 28 of file latch.h.
◆ Latch() [1/3]
CppCommon::Latch::Latch |
( |
int |
threads | ) |
|
|
inlineexplicitnoexcept |
Default class constructor.
- Parameters
-
threads | - Latch threads counter initial value |
Definition at line 11 of file latch.inl.
◆ Latch() [2/3]
CppCommon::Latch::Latch |
( |
const Latch & |
| ) |
|
|
delete |
◆ Latch() [3/3]
CppCommon::Latch::Latch |
( |
Latch && |
| ) |
|
|
delete |
◆ ~Latch()
CppCommon::Latch::~Latch |
( |
| ) |
|
|
default |
◆ CountDown()
void CppCommon::Latch::CountDown |
( |
| ) |
|
|
noexcept |
◆ CountDownAndWait()
void CppCommon::Latch::CountDownAndWait |
( |
| ) |
|
|
noexcept |
Countdown the latch.
Decrements the latch counter by 1. If the latch counter is not 0, blocks the calling thread until the latch counter is decremented to 0 by one or more other threads calling CountDown() or CountDownAndWait().
Will block.
Definition at line 50 of file latch.cpp.
◆ operator=() [1/2]
Latch& CppCommon::Latch::operator= |
( |
const Latch & |
| ) |
|
|
delete |
◆ operator=() [2/2]
◆ Reset()
void CppCommon::Latch::Reset |
( |
int |
threads | ) |
|
|
noexcept |
Reset the latch with a new threads counter value.
This method may only be invoked when there are no other threads currently inside the waiting for the latch.
Will not block.
- Parameters
-
threads | - Latch threads counter value |
Definition at line 13 of file latch.cpp.
◆ threads()
int CppCommon::Latch::threads |
( |
| ) |
const |
|
inlinenoexcept |
Get the count of threads to wait for the latch.
Definition at line 44 of file latch.h.
◆ TryWait()
bool CppCommon::Latch::TryWait |
( |
| ) |
|
|
noexcept |
Try to wait for the latch without block.
Will not block.
- Returns
- 'true' if the latch counter is zero, 'false' if the latch counter is not zero
Definition at line 80 of file latch.cpp.
◆ TryWaitFor()
bool CppCommon::Latch::TryWaitFor |
( |
const Timespan & |
timespan | ) |
|
|
inlinenoexcept |
Try to wait for the latch for the given timespan.
Will block for the given timespan in the worst case.
- Parameters
-
timespan | - Timepan to wait for the latch |
- Returns
- 'true' if the latch counter is zero, 'false' if the latch counter is not zero
Definition at line 16 of file latch.inl.
◆ TryWaitUntil()
bool CppCommon::Latch::TryWaitUntil |
( |
const Timestamp & |
timestamp | ) |
|
|
inlinenoexcept |
Try to wait for the latch until the given timestamp.
Will block until the given timestamp in the worst case.
- Parameters
-
timestamp | - Timestamp to stop wait for the latch |
- Returns
- 'true' if the latch counter is zero, 'false' if the latch counter is not zero
Definition at line 31 of file latch.inl.
◆ Wait()
void CppCommon::Latch::Wait |
( |
| ) |
|
|
noexcept |
The documentation for this class was generated from the following files: