Class for creating a semaphore. More...
Public Member Functions | |
Semaphore (uint32_t uCount=0) noexcept | |
Initialize a semaphore. | |
~Semaphore () | |
Shut down a semaphore. | |
eError | signal (void) noexcept |
Signal a semaphore. | |
eError | wait_for_signal (uint32_t uMilliseconds=0) noexcept |
Wait for a resource with a timeout. | |
uint32_t | get_value (void) const noexcept |
Get the current number of available resources. | |
Protected Attributes | |
volatile uint32_t | m_uCount |
Semaphore count value. | |
Private Member Functions | |
Semaphore (const Semaphore &)=delete | |
Semaphore & | operator= (const Semaphore &)=delete |
Semaphore (Semaphore &&)=delete | |
Semaphore & | operator= (Semaphore &&)=delete |
Class for creating a semaphore.
In a multiprocessor system, it's necessary to have multiple resources available to multiple threads at the same time. To prevent resource starvation, this class is decremented until the number of available resources is exhausted and then it will halt future threads from executing until resources are made available via calls to signal().
Further reading http://en.wikipedia.org/wiki/Semaphore_(programming)
|
privatedelete |
|
privatedelete |
|
noexcept |
Initialize a semaphore.
Query the operating system for a semaphore and initialize it to the initial value.
uCount | Initial number of resources available (0 means a empty semaphore) |
Burger::Semaphore::~Semaphore | ( | ) |
Shut down a semaphore.
Release any operating system resources allocated in the creation of the semaphore.
|
inlinenoexcept |
Get the current number of available resources.
|
noexcept |
Signal a semaphore.
When a resource is made available, signal that one is available with this call. This function will increment the count, and may release a waiting thread.
|
noexcept |
Wait for a resource with a timeout.
If the semaphore's resource count has not gone to zero or less, decrement the count and immediately return. Otherwise, block until another thread posts to the semaphore or the time in milliseconds has elapsed. If the timeout is zero, do not block.
uMilliseconds | Number of milliseconds to wait for the resource, 0 means no wait, UINT32_MAX means never time out |
|
protected |
Semaphore count value.