CppCommon
1.0.4.1
C++ Common Library
|
Named semaphore synchronization primitive. More...
#include <named_semaphore.h>
Public Member Functions | |
NamedSemaphore (const std::string &name, int resources) | |
Default class constructor. More... | |
NamedSemaphore (const NamedSemaphore &)=delete | |
NamedSemaphore (NamedSemaphore &&semaphore)=delete | |
~NamedSemaphore () | |
NamedSemaphore & | operator= (const NamedSemaphore &)=delete |
NamedSemaphore & | operator= (NamedSemaphore &&semaphore)=delete |
const std::string & | name () const |
Get the semaphore name. More... | |
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... | |
Named semaphore synchronization primitive.
Named semaphore behaves as a simple semaphore but could be shared between processes on the same machine.
Thread-safe.
Definition at line 29 of file named_semaphore.h.
|
explicit |
Default class constructor.
Definition at line 184 of file named_semaphore.cpp.
|
delete |
|
delete |
CppCommon::NamedSemaphore::~NamedSemaphore | ( | ) |
Definition at line 195 of file named_semaphore.cpp.
void CppCommon::NamedSemaphore::Lock | ( | ) |
const std::string & CppCommon::NamedSemaphore::name | ( | ) | const |
Get the semaphore name.
Definition at line 201 of file named_semaphore.cpp.
|
delete |
|
delete |
|
noexcept |
Get the semaphore resources counter.
Definition at line 202 of file named_semaphore.cpp.
bool CppCommon::NamedSemaphore::TryLock | ( | ) |
Try to acquire semaphore without block.
Will not block.
Definition at line 204 of file named_semaphore.cpp.
bool CppCommon::NamedSemaphore::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 205 of file named_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 73 of file named_semaphore.h.
void CppCommon::NamedSemaphore::Unlock | ( | ) |
Release semaphore.
Will not block.
Definition at line 208 of file named_semaphore.cpp.