CoopSync for TBB 0.1.0
Cooperative synchronization primitives for TBB resumable tasks
Loading...
Searching...
No Matches
coopsync_tbb::counting_semaphore< 1 > Class Reference

A specialization of a counting_semaphore handling only a single permit. Same as binary_semaphore. More...

#include <coopsync_tbb/semaphore.hpp>

Public Member Functions

 counting_semaphore (std::ptrdiff_t desired)
 Constructs a counting_semaphore with the specified initial count.
 counting_semaphore (const counting_semaphore &)=delete
 counting_semaphore is not copy-constructible.
counting_semaphore & operator= (const counting_semaphore &)=delete
 counting_semaphore is not copy-assignable.
 counting_semaphore (counting_semaphore &&)=delete
 counting_semaphore is not move-constructible.
counting_semaphore & operator= (counting_semaphore &&)=delete
 counting_semaphore is not move-assignable.
 ~counting_semaphore ()
 Destroys the counting_semaphore.
void release (std::ptrdiff_t update=1)
 Releases the semaphore incrementing the counter by the specified update. If there are tasks suspended on the semaphore and the counter becomes greater than zero, one of them is resumed.
void acquire ()
 Acquires the semaphore. If the semaphore is already acquired the calling task is suspended until the semaphore is released.
bool try_acquire ()
 Attempts to acquire the semaphore without suspending.

Static Public Member Functions

static constexpr std::ptrdiff_t max () noexcept
 Returns the maximum value for the counter of the binary semaphore.

Detailed Description

A specialization of a counting_semaphore handling only a single permit. Same as binary_semaphore.

Constructor & Destructor Documentation

◆ counting_semaphore()

coopsync_tbb::counting_semaphore< 1 >::counting_semaphore ( std::ptrdiff_t desired)
explicit

Constructs a counting_semaphore with the specified initial count.

Parameters
desiredThe initial count. Must be 0 or 1.

◆ ~counting_semaphore()

Destroys the counting_semaphore.

Note
The destructor must not be called while there are still tasks waiting on the counting_semaphore. The destructor does not notify or resume any waiting tasks.

Member Function Documentation

◆ acquire()

void coopsync_tbb::counting_semaphore< 1 >::acquire ( )

Acquires the semaphore. If the semaphore is already acquired the calling task is suspended until the semaphore is released.

Note
The suspended task must remain valid until it is resumed.
The suspended task must be resumed before the binary_semaphore is destroyed.

◆ max()

std::ptrdiff_t coopsync_tbb::counting_semaphore< 1 >::max ( )
inlinestaticconstexprnoexcept

Returns the maximum value for the counter of the binary semaphore.

Returns
Always returns 1.

◆ release()

void coopsync_tbb::counting_semaphore< 1 >::release ( std::ptrdiff_t update = 1)

Releases the semaphore incrementing the counter by the specified update. If there are tasks suspended on the semaphore and the counter becomes greater than zero, one of them is resumed.

Parameters
updateThe value to increment the counter by. Must be non-negative, all positive values are treated as 1.

◆ try_acquire()

bool coopsync_tbb::counting_semaphore< 1 >::try_acquire ( )
nodiscard

Attempts to acquire the semaphore without suspending.

Returns
true if the semaphore was successfully acquired, false otherwise.

The documentation for this class was generated from the following file: