Yate

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Friends | List of all members
Semaphore Class Reference

Semaphore implementation. More...

`#include <yateclass.h>`

Inheritance diagram for Semaphore:

## Public Member Functions
| 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 Member Functions inherited from Lockable
virtual | ~Lockable ()
virtual bool | check (long maxwait=-1)
virtual bool | unlockAll ()

## Static Public Member Functions
static int | count ()
static int | locks ()
static bool | efficientTimedLock ()
Static Public Member Functions inherited from Lockable
static void | wait (unsigned long maxwait)
static unsigned long | wait ()
static void | startUsingNow ()
static void | enableSafety (bool safe=true)
static bool | safety ()

## Friends
class | SemaphorePrivate

## Detailed Description

Semaphore implementation.

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

## Constructor & Destructor Documentation

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

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

Copy constructor, creates a shared semaphore

Parameters

  original | Reference of the semaphore to share

~Semaphore | ( |  | ) |

Destroy the semaphore

## Member Function Documentation

static int count | ( |  | ) |
| static

Get the number of semaphores counting the shared ones only once

Returns
  Count of individual semaphores

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

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.

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.

static int locks | ( |  | ) |
| static

Get the number of currently locked (waiting) semaphores

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

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

Assignment operator makes the semaphore shared with the original

Parameters

  original | Reference of the semaphore to share

virtual bool unlock | ( |  | ) |
| virtual

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:

- yateclass.h