CppCommon
1.0.4.1
C++ Common Library
|
Semaphore synchronization primitive. More...
#include <semaphore.h>
Public Member Functions | |
Semaphore (int resources) | |
Default class constructor. More... | |
Semaphore (const Semaphore &)=delete | |
Semaphore (Semaphore &&semaphore)=delete | |
~Semaphore () | |
Semaphore & | operator= (const Semaphore &)=delete |
Semaphore & | operator= (Semaphore &&semaphore)=delete |
int | resources () const noexcept |
Get the semaphore resources counter. More... | |
bool | TryLock () |
Try to acquire semaphore without block. More... | |
bool | TryLockFor (const Timespan ×pan) |
Try to acquire semaphore for the given timespan. More... | |
bool | TryLockUntil (const UtcTimestamp ×tamp) |
Try to acquire semaphore until the given timestamp. More... | |
void | Lock () |
Acquire semaphore with block. More... | |
void | Unlock () |
Release semaphore. More... | |
Semaphore synchronization primitive.
Semaphore synchronization primitive allows fixed count of threads to access some resource while other threads are waiting for it. When some thread unlocks the semaphore then one of waiting threads will lock it.
Thread-safe.
https://en.wikipedia.org/wiki/Semaphore_(programming)
Definition at line 29 of file semaphore.h.
|
explicit |
Default class constructor.
resources | - Semaphore resources counter |
Definition at line 156 of file semaphore.cpp.
|
delete |
|
delete |
CppCommon::Semaphore::~Semaphore | ( | ) |
Definition at line 167 of file semaphore.cpp.
void CppCommon::Semaphore::Lock | ( | ) |
|
noexcept |
Get the semaphore resources counter.
Definition at line 173 of file semaphore.cpp.
bool CppCommon::Semaphore::TryLock | ( | ) |
Try to acquire semaphore without block.
Will not block.
Definition at line 175 of file semaphore.cpp.
bool CppCommon::Semaphore::TryLockFor | ( | const Timespan & | timespan | ) |
Try to acquire semaphore for the given timespan.
Will block for the given timespan in the worst case.
timespan | - Timespan to wait for the semaphore |
Definition at line 176 of file semaphore.cpp.
|
inline |
Try to acquire semaphore until the given timestamp.
Will block until the given timestamp in the worst case.
timestamp | - Timestamp to stop wait for the semaphore |
Definition at line 70 of file semaphore.h.
void CppCommon::Semaphore::Unlock | ( | ) |
Release semaphore.
Will not block.
Definition at line 179 of file semaphore.cpp.