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) | |
Creates a semaphore. More... | |
CSemaphore (const CSemaphore &o) | |
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... | |
Protected Attributes | |
std::mutex | m_mutex |
std::condition_variable | m_condition |
unsigned long | m_count { 0 } |
CSemaphore::CSemaphore | ( | unsigned int | initialCount, |
unsigned int | maxCount | ||
) |
|
inline |
Definition at line 43 of file CSemaphore.h.
void CSemaphore::release | ( | unsigned int | increaseCount = 1 | ) |
Increments the count of the semaphore by a given amount.
Definition at line 41 of file CSemaphore.cpp.
References m_condition, m_count, m_mutex, MRPT_END, and MRPT_START.
Referenced by mrpt::detectors::CFaceDetection::detectObjects_Impl(), mrpt::gui::CWindowDialog::OnClose(), mrpt::gui::C3DWindowDialog::OnClose(), CDisplayWindow_WXAPP::OnInit(), mrpt::gui::WxSubsystem::CWXMainFrame::OnTimerProcessRequests(), mrpt::hwdrivers::CNTRIPClient::private_ntrip_thread(), sem_thread_example(), mrpt::detectors::CFaceDetection::thread_checkIfDiagonalSurface(), mrpt::detectors::CFaceDetection::thread_checkIfFacePlaneCov(), mrpt::detectors::CFaceDetection::thread_checkIfFaceRegions(), mrpt::gui::WxSubsystem::wxMainThread(), and mrpt::detectors::CFaceDetection::~CFaceDetection().
bool 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. |
Definition at line 24 of file CSemaphore.cpp.
References m_condition, m_count, m_mutex, MRPT_END, and MRPT_START.
Referenced by mrpt::hwdrivers::CNTRIPClient::close(), mrpt::gui::WxSubsystem::createOneInstanceMainThread(), mrpt::detectors::CFaceDetection::detectObjects_Impl(), mrpt::hwdrivers::CNTRIPClient::open(), mrpt::hwdrivers::prepareVideoSourceFromUserSelection(), sem_thread_example(), mrpt::detectors::CFaceDetection::thread_checkIfDiagonalSurface(), mrpt::detectors::CFaceDetection::thread_checkIfFacePlaneCov(), and mrpt::detectors::CFaceDetection::thread_checkIfFaceRegions().
|
protected |
Definition at line 35 of file CSemaphore.h.
Referenced by release(), and waitForSignal().
|
protected |
Definition at line 36 of file CSemaphore.h.
Referenced by CSemaphore(), release(), and waitForSignal().
|
protected |
Definition at line 34 of file CSemaphore.h.
Referenced by release(), and waitForSignal().
Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019 |