CppCommon
1.0.4.1
C++ Common Library
|
Read/Write lock synchronization primitive. More...
#include <rw_lock.h>
Public Member Functions | |
RWLock () | |
RWLock (const RWLock &)=delete | |
RWLock (RWLock &&lock)=delete | |
~RWLock () | |
RWLock & | operator= (const RWLock &)=delete |
RWLock & | operator= (RWLock &&lock)=delete |
bool | TryLockRead () |
Try to acquire read lock without block. More... | |
bool | TryLockWrite () |
Try to acquire write lock without block. More... | |
bool | TryLockReadFor (const Timespan ×pan) |
Try to acquire read lock for the given timespan. More... | |
bool | TryLockWriteFor (const Timespan ×pan) |
Try to acquire write lock for the given timespan. More... | |
bool | TryLockReadUntil (const UtcTimestamp ×tamp) |
Try to acquire read lock until the given timestamp. More... | |
bool | TryLockWriteUntil (const UtcTimestamp ×tamp) |
Try to acquire write lock until the given timestamp. More... | |
void | LockRead () |
Acquire read lock with block. More... | |
void | LockWrite () |
Acquire write lock with block. More... | |
void | UnlockRead () |
Release read lock. More... | |
void | UnlockWrite () |
Release write lock. More... | |
Read/Write lock synchronization primitive.
An read/write lock allows concurrent access for read-only operations, while write operations require exclusive access. This means that multiple threads can read the data in parallel but an exclusive lock is needed for writing or modifying data. When a writer is writing the data, all other writers or readers will be blocked until the writer is finished writing.
Thread-safe.
https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock
CppCommon::RWLock::RWLock | ( | ) |
Definition at line 129 of file rw_lock.cpp.
|
delete |
|
delete |
CppCommon::RWLock::~RWLock | ( | ) |
Definition at line 140 of file rw_lock.cpp.
void CppCommon::RWLock::LockRead | ( | ) |
void CppCommon::RWLock::LockWrite | ( | ) |
bool CppCommon::RWLock::TryLockRead | ( | ) |
Try to acquire read lock without block.
Will not block.
Definition at line 146 of file rw_lock.cpp.
bool CppCommon::RWLock::TryLockReadFor | ( | const Timespan & | timespan | ) |
Try to acquire read lock for the given timespan.
Will block for the given timespan in the worst case.
timespan | - Timespan to wait for the read lock |
Definition at line 149 of file rw_lock.cpp.
|
inline |
Try to acquire read lock until the given timestamp.
Will block until the given timestamp in the worst case.
timestamp | - Timestamp to stop wait for the read lock |
bool CppCommon::RWLock::TryLockWrite | ( | ) |
Try to acquire write lock without block.
Will not block.
Definition at line 147 of file rw_lock.cpp.
bool CppCommon::RWLock::TryLockWriteFor | ( | const Timespan & | timespan | ) |
Try to acquire write lock for the given timespan.
Will block for the given timespan in the worst case.
timespan | - Timespan to wait for the write lock |
Definition at line 173 of file rw_lock.cpp.
|
inline |
Try to acquire write lock until the given timestamp.
Will block until the given timestamp in the worst case.
timestamp | - Timestamp to stop wait for the write lock |
void CppCommon::RWLock::UnlockRead | ( | ) |
void CppCommon::RWLock::UnlockWrite | ( | ) |