Semaphore Class Reference

A counting semaphore -- a synchronization primitive that allows multiple processes to coordinate access to a shared resource. More...

#include <Semaphore.h++>

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

List of all members.

Public Member Functions

 Semaphore (const String &name, uint_t value=1, const Permissions &perm=Permissions::USER_READ_WRITE)
 Construct a new Semaphore with the given name, initial value, and permissions.
 ~Semaphore () throw ()
 Destructor.
void init () throw (SystemException)
 Initialize the semaphore.
bool wait () throw ()
 Wait on the semaphore.
void lock () throw ()
 Equivalent to wait().
bool tryWait () throw ()
 Try to wait on the semaphore, returning immediately if it couldn't be acquired.
bool signal () throw ()
 Signal the semaphore.
void unlock () throw ()
 Equivalent to signal().
int getValue () const throw ()
 Get the current value of the semaphore.
String getName () const
 Get the name of the semaphore.

Detailed Description

A counting semaphore -- a synchronization primitive that allows multiple processes to coordinate access to a shared resource.

A Semaphore has an initial value, which represents the quantity of some shared resource. When a process acquires the semaphore, this value is decremented, and when it releases the semaphore, the value is incremented.

A Semaphore must be initialized before it can be used, via a call to the init() method.

Author:
Mark Lindner

Constructor & Destructor Documentation

Semaphore ( const String name,
uint_t  value = 1,
const Permissions perm = Permissions::USER_READ_WRITE 
)

Construct a new Semaphore with the given name, initial value, and permissions.

Parameters:
name The name of the semaphore. On POSIX systems, the name must consist of at most 14 alphanumeric characters and may not contain slashes.
value The initial value of the semaphore. Must be at least 1.
perm The permissions with which to create the semaphore, if it does not yet exist.
~Semaphore (  )  throw ()

Destructor.

Destroys the underlying semaphore object, if no other processes have a reference to it.


Member Function Documentation

String getName (  )  const [inline]

Get the name of the semaphore.

int getValue (  )  const throw ()

Get the current value of the semaphore.

void init (  )  throw (SystemException)

Initialize the semaphore.

If the underlying semaphore object did not yet exist, it is created.

Exceptions:
SystemException If the operation fails.
void lock (  )  throw () [inline, virtual]

Equivalent to wait().

Implements Lock.

bool signal (  )  throw ()

Signal the semaphore.

Increments the semaphore's value by 1. The semaphore must have previously been acquired.

Returns:
true if the semaphore was released, false otherwise.
bool tryWait (  )  throw ()

Try to wait on the semaphore, returning immediately if it couldn't be acquired.

Returns:
true if the semaphore was acquired, false otherwise.
void unlock (  )  throw () [inline, virtual]

Equivalent to signal().

Implements Lock.

bool wait (  )  throw ()

Wait on the semaphore.

If the semaphore's value is greater than 0, it's value is decremented and the method returns. Otherwise, the method blocks until the value becomes greater than 0.

Returns:
true if the semaphore was acquired, false if an error occurred.

The documentation for this class was generated from the following files:
Generated on Fri Sep 3 23:49:37 2010 for libcommonc++ by  doxygen 1.6.3