A semaphore for inter-thread synchronization.
The state of a semaphore object is signaled when its count is greater than zero, and nonsignaled when its count is equal to zero. The initialCount parameter specifies the initial count. Each time a waiting thread is released because of the semaphore's signaled state, the count of the semaphore is decreased by one. Use the release function to increment a semaphore's count by a specified amount. The count can never be less than zero or greater than the value specified in the maxCount parameter.
Definition at line 31 of file CSemaphore.h.
#include <mrpt/synch/CSemaphore.h>
Public Member Functions | |
CSemaphore (unsigned int initialCount, unsigned int maxCount, const std::string &name=std::string("")) | |
Creates a semaphore. More... | |
virtual | ~CSemaphore () |
Destructor. More... | |
bool | waitForSignal (unsigned int timeout_ms=0) |
Blocks until the count of the semaphore to be non-zero. More... | |
void | release (unsigned int increaseCount=1) |
Increments the count of the semaphore by a given amount. More... | |
std::string | getName () const |
Get the name of the named semaphore or an empty string if it's unnamed. More... | |
bool | isNamed () const |
Return true if this is a named semaphore. More... | |
Protected Attributes | |
mrpt::utils::CReferencedMemBlock | m_data |
std::string | m_name |
The name of the named semaphore, or empty if unnamed. More... | |
mrpt::synch::CSemaphore::CSemaphore | ( | unsigned int | initialCount, |
unsigned int | maxCount, | ||
const std::string & | name = std::string("") |
||
) |
Creates a semaphore.
If name is not an empty string, a named semaphore is created. In that case if the semaphore didn't exist it's created. Otherwise, the existing semaphore is linked to this object and then initialCount and maxCount are ignored.
|
virtual |
Destructor.
|
inline |
Get the name of the named semaphore or an empty string if it's unnamed.
Definition at line 65 of file CSemaphore.h.
|
inline |
Return true if this is a named semaphore.
Definition at line 68 of file CSemaphore.h.
void mrpt::synch::CSemaphore::release | ( | unsigned int | increaseCount = 1 | ) |
Increments the count of the semaphore by a given amount.
bool mrpt::synch::CSemaphore::waitForSignal | ( | unsigned int | timeout_ms = 0 | ) |
Blocks until the count of the semaphore to be non-zero.
timeout_ms | The timeout in milliseconds, or set to zero to wait indefinidely. |
|
protected |
Definition at line 34 of file CSemaphore.h.
|
protected |
The name of the named semaphore, or empty if unnamed.
Definition at line 35 of file CSemaphore.h.
Page generated by Doxygen 1.8.11 for MRPT 1.4.0 SVN:Unversioned directory at Mon Jul 4 10:31:07 UTC 2016 |