ucommon

semaphore Class Reference

A portable counting semaphore class. More...

#include <thread.h>

Inheritance diagram for semaphore:
Collaboration diagram for semaphore:

Public Member Functions

unsigned getCount (void)
 Get active semaphore limit.
unsigned getUsed (void)
 Get current semaphore usage.
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.
void set (unsigned count)
 Alter semaphore limit at runtime.
bool wait (timeout_t timeout)
 Wait until the semphore usage count is less than the thread limit.
void wait (void)
 Wait until the semphore usage count is less than the thread limit.

Static Public Member Functions

static void release (semaphore &sync)
 Convenience class to release a semaphore.
static void wait (semaphore &sync)
 Convenience class to wait on a semaphore.
static bool wait (semaphore &sync, timeout_t timeout)
 Convenience class to wait on a semaphore.

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 1014 of file thread.h.


Member Function Documentation

unsigned semaphore::getCount ( void  )

Get active semaphore limit.

Returns:
count of maximum threads to pass.
unsigned semaphore::getUsed ( void  )

Get current semaphore usage.

Returns:
number of active threads.
static void semaphore::release ( semaphore sync) [inline, static]

Convenience class to release a semaphore.

Parameters:
syncobject to release.

Definition at line 1098 of file thread.h.

Here is the call graph for this function:

void semaphore::set ( unsigned  count)

Alter semaphore limit at runtime.

Parameters:
countof threads to allow.
static void semaphore::wait ( semaphore sync) [inline, static]

Convenience class to wait on a semaphore.

Parameters:
syncobject to wait on.

Definition at line 1082 of file thread.h.

Here is the call graph for this function:

bool semaphore::wait ( timeout_t  timeout)

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 Conditional.

static bool semaphore::wait ( semaphore sync,
timeout_t  timeout 
) [inline, static]

Convenience class to wait on a semaphore.

Parameters:
syncobject to wait on.
timeoutin milliseconds.
Returns:
if success, false if timeout.

Definition at line 1091 of file thread.h.

Here is the call graph for this function:

void 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 Conditional.


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