Semaphore implementation.
More...
#include <yateclass.h>
Semaphore implementation.
A semaphore object for synchronizing threads, can also be used as a token bucket
◆ Semaphore() [1/2]
| Semaphore |
( |
unsigned int | maxcount = 1, |
|
|
const char * | name = 0, |
|
|
unsigned int | initialCount = 1 ) |
|
explicit |
Construct a new unlocked semaphore
- Parameters
-
| maxcount | Maximum unlock count, must be strictly positive |
| name | Static name of the semaphore (for debugging purpose only) |
| initialCount | Initial semaphore count, must not be greater than maxcount |
Referenced by operator=(), and Semaphore().
◆ Semaphore() [2/2]
Copy constructor, creates a shared semaphore
- Parameters
-
| original | Reference of the semaphore to share |
References Semaphore().
◆ ~Semaphore()
◆ count()
Get the number of semaphores counting the shared ones only once
- Returns
- Count of individual semaphores
◆ efficientTimedLock()
| static bool efficientTimedLock |
( |
| ) |
|
|
static |
Check if a timed lock() is efficient on this platform
- Returns
- True if a lock with a maxwait parameter is efficiently implemented
◆ lock()
| virtual bool lock |
( |
long | maxwait = -1 | ) |
|
|
virtual |
Attempt to get a lock on the semaphore and eventually wait for it
- Parameters
-
| maxwait | Time in microseconds to wait, -1 wait forever |
- Returns
- True if successfully locked, false on failure
Implements Lockable.
◆ locked()
| virtual bool locked |
( |
| ) |
const |
|
virtual |
Check if the semaphore is currently locked (waiting) - as it's asynchronous it guarantees nothing if other thread changes status
- Returns
- True if the semaphore was locked when the function was called
Implements Lockable.
◆ locks()
Get the number of currently locked (waiting) semaphores
- Returns
- Count of locked semaphores, -1 if unknown (not tracked)
◆ operator=()
Assignment operator makes the semaphore shared with the original
- Parameters
-
| original | Reference of the semaphore to share |
References Semaphore().
◆ unlock()
Unlock the semaphore, does never wait nor get over counter maximum
- Returns
- True if successfully unlocked
Implements Lockable.
The documentation for this class was generated from the following file: