The Micro C++ Library
micxx::Semaphore Class Reference

The Semaphore implements a counting semaphore with the ability of claiming or returning more than one unit from the semaphore and with support for timeout detection. More...

#include <micxx.hxx>

Inherits micxx::Condition.

List of all members.

Public Member Functions

 Semaphore (int initialValue=1)
 Create a new Semaphore with initialValue.
virtual unsigned getValue () const
 The current counter value.
virtual bool acquire (int avalue=1, unsigned long timeoutMillis=0)
 Try to acquire the unit avalue of the counter value within timeoutMillis.
virtual void release (int avalue=1)
 Release the unit avalue of the counter value.

Detailed Description

The Semaphore implements a counting semaphore with the ability of claiming or returning more than one unit from the semaphore and with support for timeout detection.

If s is the internal kept counter value, the Semaphore is implemented in the following way:

 Semaphore::acquire(int howmany[, unsigned long timeout])
 {
     wait until s >= 0;
     s := s - howmany; // must be atomic operation
     wait until s >= 0;
 }

 Semaphore::release(int howmany)
 {
     s := s+howmany;   // must be atomic
 }
Author:
Norbert Klose
Date:
December, 2006

Constructor & Destructor Documentation

micxx::Semaphore::Semaphore ( int  initialValue = 1)

Create a new Semaphore with initialValue.

Parameters:
initialValueThe initial counter value. This is the maximum value which could be acquired without blocking the current calling thread.

Member Function Documentation

virtual bool micxx::Semaphore::acquire ( int  avalue = 1,
unsigned long  timeoutMillis = 0 
) [virtual]

Try to acquire the unit avalue of the counter value within timeoutMillis.

Parameters:
avalueThe unit of the counter value to be acquired at once.
timeoutMillisIf greater 0, wait at most timeoutMillis until the call returns (regardless if the lock has successfully been acquired or not).
Returns:
true, if the lock has been successfully acquired,
false, otherwise.
virtual unsigned micxx::Semaphore::getValue ( ) const [virtual]

The current counter value.

This is the maximum value which could be acquired without blocking the current calling thread.

virtual void micxx::Semaphore::release ( int  avalue = 1) [virtual]

Release the unit avalue of the counter value.


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