Quick Links: |
#include <bslmt_semaphore.h>
Public Member Functions | |
Semaphore () | |
Semaphore (int count) | |
~Semaphore () | |
void | post () |
void | post (int value) |
int | tryWait () |
void | wait () |
int | getValue () const |
This class implements a portable semaphore type for thread synchronization. It forwards all requests to an appropriate platform-specific implementation.
bslmt::Semaphore::Semaphore | ( | ) |
Create a semaphore initially having a count of 0.
bslmt::Semaphore::Semaphore | ( | int | count | ) | [explicit] |
Create a semaphore initially having the specified count
.
bslmt::Semaphore::~Semaphore | ( | ) |
Destroy this semaphore.
void bslmt::Semaphore::post | ( | ) |
Atomically increment the count of this semaphore.
void bslmt::Semaphore::post | ( | int | value | ) |
Atomically increase the count of this semaphore by the specified value
. The behavior is undefined unless value > 0
.
int bslmt::Semaphore::tryWait | ( | ) |
If the count of this semaphore is positive, atomically decrement the count and return 0; otherwise, return a non-zero value with no effect on the count.
void bslmt::Semaphore::wait | ( | ) |
Block until the count of this semaphore is a positive value, then atomically decrement the count and return.
int bslmt::Semaphore::getValue | ( | ) | const |
Return the value of the current count of this semaphore.