CppCommon
1.0.4.1
C++ Common Library
|
Critical section synchronization primitive. More...
#include <critical_section.h>
Public Member Functions | |
CriticalSection () | |
CriticalSection (const CriticalSection &)=delete | |
CriticalSection (CriticalSection &&cs)=delete | |
~CriticalSection () | |
CriticalSection & | operator= (const CriticalSection &)=delete |
CriticalSection & | operator= (CriticalSection &&cs)=delete |
bool | TryLock () |
Try to acquire critical section without block. More... | |
bool | TryLockFor (const Timespan ×pan) |
Try to acquire critical section for the given timespan. More... | |
bool | TryLockUntil (const UtcTimestamp ×tamp) |
Try to acquire critical section until the given timestamp. More... | |
void | Lock () |
Acquire critical section with block. More... | |
void | Unlock () |
Release critical section. More... | |
Friends | |
class | ConditionVariable |
Critical section synchronization primitive.
Critical sections prevents code fragments from access by multiple threads simultaneously. Only one thread can access the code inside the critical section. Other threads must wait for the lock! Critical sections are usually more lightweight than mutexes and don't enter kernel mode.
Thread-safe.
https://en.wikipedia.org/wiki/Critical_section
Definition at line 29 of file critical_section.h.
CppCommon::CriticalSection::CriticalSection | ( | ) |
Definition at line 110 of file critical_section.cpp.
|
delete |
|
delete |
CppCommon::CriticalSection::~CriticalSection | ( | ) |
Definition at line 121 of file critical_section.cpp.
void CppCommon::CriticalSection::Lock | ( | ) |
Acquire critical section with block.
Will block.
Definition at line 155 of file critical_section.cpp.
|
delete |
|
delete |
bool CppCommon::CriticalSection::TryLock | ( | ) |
Try to acquire critical section without block.
Will not block.
Definition at line 129 of file critical_section.cpp.
bool CppCommon::CriticalSection::TryLockFor | ( | const Timespan & | timespan | ) |
Try to acquire critical section for the given timespan.
Will block for the given timespan in the worst case.
timespan | - Timespan to wait for the critical section |
Definition at line 131 of file critical_section.cpp.
|
inline |
Try to acquire critical section until the given timestamp.
Will block until the given timestamp in the worst case.
timestamp | - Timestamp to stop wait for the critical section |
Definition at line 65 of file critical_section.h.
void CppCommon::CriticalSection::Unlock | ( | ) |
Release critical section.
Will not block.
Definition at line 156 of file critical_section.cpp.
|
friend |
Definition at line 31 of file critical_section.h.