UCommon
|
A portable counting semaphore class. More...
#include <thread.h>
Public Member Functions | |
void | operator++ (void) |
Convenience operator to wait on a counting semaphore. | |
void | operator-- (void) |
Convenience operator to release a counting semaphore. | |
void | release (void) |
Release the semaphore after waiting for it. | |
Semaphore (unsigned count=0) | |
Construct a semaphore with an initial count of threads to permit. | |
void | set (unsigned count) |
Alter semaphore limit at runtime. More... | |
void | wait (void) |
Wait until the semphore usage count is less than the thread limit. More... | |
bool | wait (timeout_t timeout) |
Wait until the semphore usage count is less than the thread limit. More... | |
![]() | |
virtual void | exclusive (void) |
Convert object to an exclusive lock. More... | |
void | release_share (void) |
virtual void | share (void) |
Share the lock with other referencers. More... | |
void | shared_lock (void) |
Protected Member Functions | |
virtual void | _share (void) |
Access interface to share lock the object. | |
virtual void | _unlock (void) |
![]() | |
void | broadcast (void) |
Signal the conditional to release all waiting threads. | |
Conditional () | |
Initialize and construct conditional. | |
void | lock (void) |
Lock the conditional's supporting mutex. | |
void | signal (void) |
Signal the conditional to release one waiting thread. | |
void | unlock (void) |
Unlock the conditional's supporting mutex. | |
bool | wait (timeout_t timeout) |
Conditional wait for signal on millisecond timeout. More... | |
bool | wait (struct timespec *timeout) |
Conditional wait for signal on timespec timeout. More... | |
void | wait (void) |
Wait (block) until signalled. | |
~Conditional () | |
Destroy conditional, release any blocked threads. | |
Protected Attributes | |
unsigned | count |
unsigned | used |
unsigned | waits |
Additional Inherited Members | |
![]() | |
static pthread_condattr_t * | initializer (void) |
Support function for getting conditional attributes for realtime scheduling. More... | |
static void | set (struct timespec *hires, timeout_t timeout) |
Convert a millisecond timeout into use for high resolution conditional timers. More... | |
A portable counting semaphore class.
A semaphore will allow threads to pass through it until the count is reached, and blocks further threads. Unlike pthread semaphore, our semaphore class supports it's count limit to be altered during runtime and the use of timed waits. This class also implements the shared_lock protocol.
void ucommon::Semaphore::set | ( | unsigned | count | ) |
Alter semaphore limit at runtime.
count | of threads to allow. |
void ucommon::Semaphore::wait | ( | void | ) |
Wait until the semphore usage count is less than the thread limit.
Increase used count for our thread when unblocked.
bool ucommon::Semaphore::wait | ( | timeout_t | timeout | ) |
Wait until the semphore usage count is less than the thread limit.
Increase used count for our thread when unblocked, or return without changing if timed out.
timeout | to wait in millseconds. |