A portable counting semaphore class.
More...
#include <thread.h>
Public Member Functions |
unsigned | getCount (void) |
| Get active semaphore limit.
|
unsigned | getUsed (void) |
| Get current semaphore usage.
|
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.
|
void | wait (void) |
| Wait until the semphore usage count is less than the thread limit.
|
bool | wait (timeout_t timeout) |
| Wait until the semphore usage count is less than the thread limit.
|
virtual void | Exclusive (void) |
| Convert object to an exclusive lock.
|
void | Lock (void) |
| A convenience member function for accessing the shared lock.
|
virtual void | Share (void) |
| Share the lock with other referencers.
|
Static Public Member Functions |
static void | release (Semaphore &sync) |
| Convenience class to release a semaphore.
|
static void | wait (Semaphore &sync) |
| Convenience class to wait on a semaphore.
|
static bool | wait (Semaphore &sync, timeout_t timeout) |
| Convenience class to wait on a semaphore.
|
Protected Member Functions |
void | Shlock (void) |
| Protocol interface to share lock the object.
|
void | Unlock (void) |
| Protocol interface to release a lock.
|
Protected Attributes |
unsigned | count |
unsigned | used |
unsigned | waits |
Additional Inherited Members |
static void | gettimeout (timeout_t timeout, struct timespec *hires) |
| Convert a millisecond timeout into use for high resolution conditional timers.
|
static pthread_condattr_t * | initializer (void) |
| Support function for getting conditional attributes for realtime scheduling.
|
Detailed Description
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 1023 of file thread.h.
Member Function Documentation
unsigned ucommon::Semaphore::getCount |
( |
void |
| ) |
|
Get active semaphore limit.
- Returns:
- count of maximum threads to pass.
unsigned ucommon::Semaphore::getUsed |
( |
void |
| ) |
|
Get current semaphore usage.
- Returns:
- number of active threads.
static void ucommon::Semaphore::release |
( |
Semaphore & |
sync | ) |
|
|
inlinestatic |
Convenience class to release a semaphore.
- Parameters:
-
Definition at line 1107 of file thread.h.
void ucommon::Semaphore::set |
( |
unsigned |
count | ) |
|
Alter semaphore limit at runtime.
- Parameters:
-
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.
Reimplemented from ucommon::Conditional.
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.
Reimplemented from ucommon::Conditional.
static void ucommon::Semaphore::wait |
( |
Semaphore & |
sync | ) |
|
|
inlinestatic |
Convenience class to wait on a semaphore.
- Parameters:
-
Definition at line 1091 of file thread.h.
Convenience class to wait on a semaphore.
- Parameters:
-
sync | object to wait on. |
timeout | in milliseconds. |
- Returns:
- if success, false if timeout.
Definition at line 1100 of file thread.h.
The documentation for this class was generated from the following file: