Semaphore management. More...
#include <Inventor/threads/SbThreadSemaphore.h>
Public Member Functions | |
SbThreadSemaphore (int initialCount, int maxCount=-1) | |
~SbThreadSemaphore () | |
void | wait () |
SbBool | trywait (const unsigned int timeout_ms=0) |
void | release () |
void | changeCount (int) |
Semaphore management.
Class managing a semaphore. A semaphore is a non-negative integer count and is generally used to coordinate access to resources. The initial semaphore count is set to the number of free resources, then threads slowly increment and decrement the count as resources are added and removed. If the semaphore count drops to zero, which means no available resources, threads attempting to decrement the semaphore will block until the count is greater than zero.
SbThreadSemaphore::SbThreadSemaphore | ( | int | initialCount, | |
int | maxCount = -1 | |||
) |
Semaphore constructor.
MaxCount is the maximum count of the counter. If maxCount isn't specified (=-1), it will be initialized to initialCount. If maxCount is set to -2 it will be initialized to maximum value allowed by the system (unlimited semaphore behavior).
SbThreadSemaphore::~SbThreadSemaphore | ( | ) |
Destructor.
void SbThreadSemaphore::changeCount | ( | int | ) |
Allows adding or removing resources.
void SbThreadSemaphore::release | ( | ) |
Releases the semaphore.
This call increases the semaphore count.
SbBool SbThreadSemaphore::trywait | ( | const unsigned int | timeout_ms = 0 |
) |
Try to acquire the semaphore.
If the semaphore count drops to zero, which means no available resources, the thread attempting to decrement the semaphore will block until the count is greater than zero (meaning that another thread called release).
The time out parameter specifies how many milliseconds to wait before checking for release of the semaphore. By default there is no wait.
void SbThreadSemaphore::wait | ( | ) |