Semaphore Class Reference

Semaphore implementation. More...

#include <yateclass.h>

Inheritance diagram for Semaphore:
Lockable

List of all members.

Public Member Functions

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

Static Public Member Functions

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

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 
)

Construct a new unlocked semaphore

Parameters:
maxcount Maximum unlock count, must be strictly positive
name Static name of the semaphore (for debugging purpose only)
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, should be zero at program exit
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:
Generated on Thu Apr 8 18:22:35 2010 for Yate by  doxygen 1.6.3