#include <Semaphore.h>
Inheritance diagram for ZThread::Semaphore:
Public Member Functions | |
Semaphore (int count=1, unsigned int maxCount=1) | |
virtual | ~Semaphore () |
Destroy the Semaphore. | |
void | wait () |
bool | tryWait (unsigned long timeout) |
void | post () |
virtual int | count () |
virtual bool | tryAcquire (unsigned long timeout) |
virtual void | acquire () |
virtual void | release () |
A Semaphore with an initial value of 1 and maximum value of 1 will act as a Mutex.
Threads blocked on a Semaphore are resumed in FIFO order.
ZThread::Semaphore::Semaphore | ( | int | count = 1 , |
|
unsigned int | maxCount = 1 | |||
) |
void ZThread::Semaphore::acquire | ( | ) | [virtual] |
Decrement the count, blocking that calling thread if the count becomes 0 or less than 0. The calling thread will remain blocked until the count is raised above 0 or if an exception is thrown.
Interrupted_Exception | thrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending any wait. |
Implements ZThread::Lockable.
int ZThread::Semaphore::count | ( | ) | [virtual] |
Get the current count of the semaphore.
This value may change immediately after this function returns to the calling thread.
void ZThread::Semaphore::post | ( | ) |
void ZThread::Semaphore::release | ( | ) | [virtual] |
Increment the count, unblocking one thread if count is positive.
InvalidOp_Exception | thrown if the maximum count would be exceeded. |
Implements ZThread::Lockable.
bool ZThread::Semaphore::tryAcquire | ( | unsigned long | timeout | ) | [virtual] |
Decrement the count, blocking that calling thread if the count becomes 0 or less than 0. The calling thread will remain blocked until the count is raised above 0, an exception is thrown or the given amount of time expires.
timeout | maximum amount of time (milliseconds) this method could block |
Interrupted_Exception | thrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending any wait. |
Implements ZThread::Lockable.
bool ZThread::Semaphore::tryWait | ( | unsigned long | timeout | ) |
void ZThread::Semaphore::wait | ( | ) |