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. More...
#include <Semaphore.h>
Public Member Functions | |
Semaphore (const String &name, uint32 value=1, const Permissions &perm=Permissions::USER_READ_WRITE) | |
~Semaphore () | |
void | Lock () |
bool | TryWait () |
void | Unlock () |
int | GetValue () const |
const String & | GetName () const |
virtual void | ValidateMem () const |
virtual void | CheckMem () const |
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.
Definition at line 62 of file Semaphore.h.
Semaphore::Semaphore | ( | const String & | name, | |
uint32 | value = 1 , |
|||
const Permissions & | perm = Permissions::USER_READ_WRITE | |||
) |
Construct a new Semaphore with the given name, initial value, and permissions. If the underlying semaphore object did not yet exist, it is created.
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. |
Definition at line 45 of file Semaphore.cpp.
Semaphore::~Semaphore | ( | ) |
Destructor. Destroys the underlying semaphore object, if no other processes have a reference to it.
Definition at line 99 of file Semaphore.cpp.
const String& Semaphore::GetName | ( | ) | const [inline] |
Get the name of the semaphore.
Definition at line 127 of file Semaphore.h.
int Semaphore::GetValue | ( | ) | const |
Get the current value of the semaphore.
Definition at line 170 of file Semaphore.cpp.
void Semaphore::Lock | ( | ) |
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.
Definition at line 119 of file Semaphore.cpp.
bool Semaphore::TryWait | ( | ) |
Try to wait on the semaphore, returning immediately if it couldn't be acquired.
Definition at line 138 of file Semaphore.cpp.
void Semaphore::Unlock | ( | ) |
Signal the semaphore. Increments the semaphore's value by 1. The semaphore must have previously been acquired.
Definition at line 151 of file Semaphore.cpp.