UCommon
Public Member Functions | Protected Member Functions | Protected Attributes
ucommon::Semaphore Class Reference

A portable counting semaphore class. More...

#include <thread.h>

Inheritance diagram for ucommon::Semaphore:
Inheritance graph
[legend]
Collaboration diagram for ucommon::Semaphore:
Collaboration graph
[legend]

Public Member Functions

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.
 Semaphore (unsigned count, unsigned avail)
 Alternate onstructor with ability to preset available slots.
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.

Protected Member Functions

virtual void _share (void)
 Access interface to share lock the object.
virtual void _unlock (void)

Protected Attributes

unsigned count
unsigned used
unsigned waits

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@gnutelephony.org>

Definition at line 884 of file thread.h.


Constructor & Destructor Documentation

ucommon::Semaphore::Semaphore ( unsigned  count = 0)

Construct a semaphore with an initial count of threads to permit.

Parameters:
countof threads to permit, or special case 0 group release.
ucommon::Semaphore::Semaphore ( unsigned  count,
unsigned  avail 
)

Alternate onstructor with ability to preset available slots.

Parameters:
countof threads to permit.
availinstances not pre-locked.

Member Function Documentation

void ucommon::Semaphore::set ( unsigned  count)

Alter semaphore limit at runtime.

Parameters:
countof 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.

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:
timeoutto wait in millseconds.
Returns:
true if success, false if timeout.

Reimplemented from ucommon::Conditional.


The documentation for this class was generated from the following file: