Main MRPT website > C++ reference for MRPT 1.5.9
List of all members | Public Member Functions | Protected Attributes
mrpt::synch::CSemaphore Class Reference

Detailed Description

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 }

Constructor & Destructor Documentation

◆ CSemaphore() [1/2]

CSemaphore::CSemaphore ( unsigned int  initialCount,
unsigned int  maxCount 

Creates a semaphore.

Definition at line 17 of file CSemaphore.cpp.

References m_count.

◆ CSemaphore() [2/2]

mrpt::synch::CSemaphore::CSemaphore ( const CSemaphore o)

Definition at line 43 of file CSemaphore.h.

Member Function Documentation

◆ release()

void CSemaphore::release ( unsigned int  increaseCount = 1)

◆ waitForSignal()

bool CSemaphore::waitForSignal ( unsigned int  timeout_ms = 0)

Member Data Documentation

◆ m_condition

std::condition_variable mrpt::synch::CSemaphore::m_condition

Definition at line 35 of file CSemaphore.h.

Referenced by release(), and waitForSignal().

◆ m_count

unsigned long mrpt::synch::CSemaphore::m_count { 0 }

Definition at line 36 of file CSemaphore.h.

Referenced by CSemaphore(), release(), and waitForSignal().

◆ m_mutex

std::mutex mrpt::synch::CSemaphore::m_mutex

Definition at line 34 of file CSemaphore.h.

Referenced by release(), and waitForSignal().

Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020