|
The Micro C++ Library
|
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.
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. | |
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 }
| micxx::Semaphore::Semaphore | ( | int | initialValue = 1 | ) |
Create a new Semaphore with initialValue.
| initialValue | The initial counter value. This is the maximum value which could be acquired without blocking the current calling thread. |
| 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.
| avalue | The unit of the counter value to be acquired at once. |
| timeoutMillis | If greater 0, wait at most timeoutMillis until the call returns (regardless if the lock has successfully been acquired or not). |
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.