A latch is a down-ward counter that allows tasks to wait until the counter reaches zero. The latch is not reusable, i.e., once the counter reaches zero, it cannot be incremented again. Concurrent invocations of the member functions, except for destructor, are safe.
More...
#include <coopsync_tbb/latch.hpp>
|
| | latch (std::ptrdiff_t expected) |
| | Constructs a latch with the specified initial count. The count must be non-negative.
|
|
| latch (const latch &)=delete |
| | Latch is not copy-constructible.
|
|
latch & | operator= (const latch &)=delete |
| | Latch is not copy-assignable.
|
|
| latch (latch &&)=delete |
| | Latch is not move-constructible.
|
|
latch & | operator= (latch &&)=delete |
| | Latch is not move-assignable.
|
| | ~latch () |
| | Destroys the latch.
|
| bool | try_wait () const noexcept |
| | Checks if the latch has reached zero without suspending the calling task.
|
| void | count_down (std::ptrdiff_t update=1) |
| | Decrements the latch counter by the specified update. If the counter reaches zero, all suspended tasks are resumed.
|
| void | wait () |
| | Suspends the calling task until the latch counter reaches zero. If the counter is already zero, the function returns immediately.
|
| void | arrive_and_wait (std::ptrdiff_t update=1) |
| | Decrements the latch counter by the specified update and suspends until the counter reaches zero. The update must be non-negative and less than or equal to the current counter value.
|
|
| static constexpr std::ptrdiff_t | max () noexcept |
| | Returns the maximum value for the latch counter.
|
A latch is a down-ward counter that allows tasks to wait until the counter reaches zero. The latch is not reusable, i.e., once the counter reaches zero, it cannot be incremented again. Concurrent invocations of the member functions, except for destructor, are safe.
◆ latch()
| coopsync_tbb::latch::latch |
( |
std::ptrdiff_t | expected | ) |
|
|
explicit |
Constructs a latch with the specified initial count. The count must be non-negative.
- Parameters
-
| expected | The initial count for the latch. Must be non-negative and not greater than max(). |
◆ ~latch()
| coopsync_tbb::latch::~latch |
( |
| ) |
|
Destroys the latch.
- Note
- The destructor must not be called while there are still tasks waiting on the latch. The destructor does not notify or resume any waiting tasks.
◆ arrive_and_wait()
| void coopsync_tbb::latch::arrive_and_wait |
( |
std::ptrdiff_t | update = 1 | ) |
|
Decrements the latch counter by the specified update and suspends until the counter reaches zero. The update must be non-negative and less than or equal to the current counter value.
- Parameters
-
| update | The value to decrement the counter by. |
◆ count_down()
| void coopsync_tbb::latch::count_down |
( |
std::ptrdiff_t | update = 1 | ) |
|
Decrements the latch counter by the specified update. If the counter reaches zero, all suspended tasks are resumed.
- Parameters
-
| update | The value to decrement the counter by. Must be non-negative and less than or equal to the current counter value. |
◆ max()
| std::ptrdiff_t coopsync_tbb::latch::max |
( |
| ) |
|
|
inlinestaticconstexprnoexcept |
Returns the maximum value for the latch counter.
- Returns
- The maximum value for the latch counter.
◆ try_wait()
| bool coopsync_tbb::latch::try_wait |
( |
| ) |
const |
|
nodiscardnoexcept |
Checks if the latch has reached zero without suspending the calling task.
- Returns
- true if the latch has reached zero, false otherwise.
◆ wait()
| void coopsync_tbb::latch::wait |
( |
| ) |
|
Suspends the calling task until the latch counter reaches zero. If the counter is already zero, the function returns immediately.
- Note
- The suspended task must remain valid until it is resumed.
-
The suspended task must be resumed before the latch is destroyed.
The documentation for this class was generated from the following file: