class Semaphore

# class Semaphore | Semaphore implementation. More...
Full name | `TelEngine::Semaphore`
Definition | `#include <yateclass.h>`
Inherits | TelEngine::Lockable [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- explicit Semaphore (unsigned int maxcount = 1, const char* name = 0, unsigned int initialCount = 1)
- Semaphore (const Semaphore& original)
- ~Semaphore ()
- Semaphore& operator= (const Semaphore& original)
- virtual bool lock (long maxwait = -1)
- virtual bool unlock ()
- virtual bool locked () const

#### Public Static Methods

- static int count ()
- static int locks ()
- static bool efficientTimedLock ()

## Detailed Description

A semaphore object for synchronizing threads, can also be used as a token bucket

explicit Semaphore (unsigned int maxcount = 1, const char* name = 0, unsigned int initialCount = 1) | ### Semaphore

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

Semaphore (const Semaphore& original) | ### Semaphore

Copy constructor, creates a shared semaphore

Parameters:

original | Reference of the semaphore to share

~Semaphore () | ### ~Semaphore

Destroy the semaphore

Semaphore& operator= (const Semaphore& original) | ### operator=

Assignment operator makes the semaphore shared with the original

Parameters:

original | Reference of the semaphore to share

bool lock (long maxwait = -1) | ### lock

[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

Reimplemented from Lockable.

bool unlock () | ### unlock

[virtual]

Unlock the semaphore, does never wait nor get over counter maximum

Returns: True if successfully unlocked

Reimplemented from Lockable.

bool locked () | ### 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

Reimplemented from Lockable.

int count () | ### count

[static]

Get the number of semaphores counting the shared ones only once

Returns: Count of individual semaphores

int locks () | ### locks

[static]

Get the number of currently locked (waiting) semaphores

Returns: Count of locked semaphores, -1 if unknown (not tracked)

bool efficientTimedLock () | ### efficientTimedLock

[static]

Check if a timed lock() is efficient on this platform

Returns: True if a lock with a maxwait parameter is efficiently implemented

Generated by: paulc on bussard on Fri May 8 12:37:22 2015, using kdoc 2.0a54.