A portable counting semaphore class.
More...
#include <condition.h>
|
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. More...
|
|
| Semaphore (unsigned count, unsigned avail) |
| Alternate onstructor with ability to preset available slots. More...
|
|
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...
|
|
virtual void | share (void) |
| Share the lock with other referencers. More...
|
|
|
virtual void | _share (void) |
| Access interface to share lock the object.
|
|
virtual void | _unshare (void) |
|
Semaphore & | operator= (const Semaphore &) |
|
| Semaphore (const Semaphore &) |
|
void | broadcast (void) |
| Signal the conditional to release all waiting threads.
|
|
| Conditional () |
| Initialize and construct conditional.
|
|
void | signal (void) |
| Signal the conditional to release one waiting thread.
|
|
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.
|
|
| ConditionMutex () |
| Initialize and construct conditional.
|
|
void | lock (void) |
| Lock the conditional's supporting mutex.
|
|
void | unlock (void) |
| Unlock the conditional's supporting mutex.
|
|
| ~ConditionMutex () |
| Destroy conditional, release any blocked threads.
|
|
|
unsigned | count |
|
unsigned | used |
|
unsigned | waits |
|
pthread_cond_t | cond |
|
pthread_mutex_t | mutex |
|
|
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...
|
|
static attribute | attr |
|
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.
- Author
- David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org
Definition at line 655 of file condition.h.
◆ Semaphore() [1/2]
ucommon::Semaphore::Semaphore |
( |
unsigned |
count = 0 | ) |
|
Construct a semaphore with an initial count of threads to permit.
- Parameters
-
count | of threads to permit, or special case 0 group release. |
◆ Semaphore() [2/2]
ucommon::Semaphore::Semaphore |
( |
unsigned |
count, |
|
|
unsigned |
avail |
|
) |
| |
Alternate onstructor with ability to preset available slots.
- Parameters
-
count | of threads to permit. |
avail | instances not pre-locked. |
◆ set()
void ucommon::Semaphore::set |
( |
unsigned |
count | ) |
|
Alter semaphore limit at runtime.
- Parameters
-
count | of threads to allow. |
◆ wait() [1/2]
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.
◆ wait() [2/2]
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.
- Parameters
-
timeout | to wait in millseconds. |
- Returns
- true if success, false if timeout.
The documentation for this class was generated from the following file: