Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

P::Semaphore Class Reference
[Core library]

Semaphore synchronization class. More...

#include <psemaphore.h>

List of all members.

Public Member Functions

 Semaphore (const char *name=0, unsigned int initial=0) throw (SyncError)
 Default constructor.

 ~Semaphore () throw (SyncError)
 Destructor.

void wait () throw (SyncError)
 Wait for the semaphore to become signaled.

bool tryWait () throw (SyncError)
 Non-blocking wait for semaphore.

void post () throw (SyncError)
 Increases the semaphore count.


Detailed Description

Semaphore synchronization class.

Semaphores are counters for resources shared between threads or processes. The basic operations on semaphores are: increment the counter atomically, and wait until the counter is non-null and decrement it atomically.

Author:
Christian Prochnow <cproch@seculogix.de>

Definition at line 36 of file psemaphore.h.


Constructor & Destructor Documentation

P::Semaphore::Semaphore const char *  name = 0,
unsigned int  initial = 0
throw (SyncError)
 

Default constructor.

Construct's a semaphore object. The semaphore may be process- shared if a name is supplied. On systems with SYSV semaphores the name must reffer to an existing file and the process must be able to stat() the file. On systems that do not have SYSV semaphores a semaphore cannot be process shared otherwise a SyncError will be thrown.

Parameters:
name a pointer to the name of the semaphore which is used to identify the mutex, or a NULL pointer if the semaphore should be process-local.
initial the initial count the semaphore should be initialized to
Exceptions:
SyncError 

P::Semaphore::~Semaphore  )  throw (SyncError)
 

Destructor.


Member Function Documentation

void P::Semaphore::post  )  throw (SyncError)
 

Increases the semaphore count.

bool P::Semaphore::tryWait  )  throw (SyncError)
 

Non-blocking wait for semaphore.

If the semahore is signaled (count greater than zero), atomically decreases the semaphore count and returns true. If the semaphore is currently not signaled (count is equal to zero) it immediatly returns false.

Returns:
true if semaphore has been acquired, false otherwise
Exceptions:
SyncError 

void P::Semaphore::wait  )  throw (SyncError)
 

Wait for the semaphore to become signaled.

Waits for the semaphore to become signaled (count is greater than zero) and atomically decreases the semaphore count.

Exceptions:
SyncError 


The documentation for this class was generated from the following file:
Generated on Fri Mar 12 21:08:36 2004 for P::Classes by doxygen 1.3.3