Go to the documentation of this file.
11 #include <condition_variable>
97 ::std::condition_variable
cv;
108 template <
typename T>
RAII guard for operations with a semaphore. On creation, the semaphore is acquired,...
SemaphoreGuard(T &semaphore)
size_t getCount() const
Get the current number of unreleased acquire()s.
void release()
Release the semaphore (decrease its count).
::std::condition_variable cv
Condition variable used for signalling between release() and waitZero().
bool waitZeroAtDestroy
Whether to wait for zero when the object is being destroyed.
mutable ::std::mutex mutex
Mutex protecting cv, count and disabled.
bool waitZero()
Wait until the internal count reaches zero.
bool acquire()
Acquire the semaphore (increase its count). This method never blocks for long.
volatile bool disabled
Whether the semaphore is disabled.
void enable()
Enable the semaphore. Calling acquire() works normally after this call.
volatile size_t count
The internal count of the semaphore.
bool isDestroying
True if the destructor has begun.
~ReverseSemaphore()
Destroys this semaphore. Internally blocks it and waits for zero count.
bool acquired() const
Whether the semaphore acquisition succeeded when constructing this guard.
T & semaphore
The guarded semaphore.
ReverseSemaphore(bool waitZeroAtDestroy=true)
Create the semaphore (internal count is zero).
bool isEnabled() const
Whether the semaphore is enabled or not.
void disable()
Disable the semaphore. All following acquire() calls will return immediately with false.
bool acquireSucceeded
Whether the acquire succeeded.
A reverse counting semaphore which can wait until its count is zero. Each acquire() increases this co...
cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Dec 14 2024 03:51:04