|
CppCommon 1.0.5.0
C++ Common Library
|
Named read/write lock synchronization primitive. More...
#include <named_rw_lock.h>
Public Member Functions | |
| NamedRWLock (const std::string &name) | |
| Default class constructor. | |
| NamedRWLock (const NamedRWLock &)=delete | |
| NamedRWLock (NamedRWLock &&lock)=delete | |
| ~NamedRWLock () | |
| NamedRWLock & | operator= (const NamedRWLock &)=delete |
| NamedRWLock & | operator= (NamedRWLock &&lock)=delete |
| const std::string & | name () const |
| Get the read/write lock name. | |
| bool | TryLockRead () |
| Try to acquire read lock without block. | |
| bool | TryLockWrite () |
| Try to acquire write lock without block. | |
| bool | TryConvertWriteToRead () |
| Try to convert write lock to read lock without block. | |
| bool | TryLockReadFor (const Timespan ×pan) |
| Try to acquire read lock for the given timespan. | |
| bool | TryLockWriteFor (const Timespan ×pan) |
| Try to acquire write lock for the given timespan. | |
| bool | TryConvertWriteToReadFor (const Timespan ×pan) |
| Try to convert write lock to read lock for the given timespan. | |
| bool | TryLockReadUntil (const UtcTimestamp ×tamp) |
| Try to acquire read lock until the given timestamp. | |
| bool | TryLockWriteUntil (const UtcTimestamp ×tamp) |
| Try to acquire write lock until the given timestamp. | |
| bool | TryConvertWriteToReadUntil (const UtcTimestamp ×tamp) |
| Try to convert write lock to read lock until the given timestamp. | |
| void | LockRead () |
| Acquire read lock with block. | |
| void | LockWrite () |
| Acquire write lock with block. | |
| void | UnlockRead () |
| Release read lock. | |
| void | UnlockWrite () |
| Release write lock. | |
| void | ConvertWriteToRead () |
| Convert write lock to read lock without block. | |
Named read/write lock synchronization primitive.
Named read/write lock behaves as a simple read/write lock but could be shared between processes on the same machine.
The fast lock is around 7% faster than the critical section when there is no contention, when used solely for mutual exclusion. It is also much smaller than the critical section.
Thread-safe.
Definition at line 32 of file named_rw_lock.h.
|
explicit |
Default class constructor.
| name | - Read/Write lock name |
Definition at line 507 of file named_rw_lock.cpp.
|
delete |
|
delete |
| CppCommon::NamedRWLock::~NamedRWLock | ( | ) |
Definition at line 518 of file named_rw_lock.cpp.
| void CppCommon::NamedRWLock::ConvertWriteToRead | ( | ) |
Convert write lock to read lock without block.
Exclusive acquires are not given a chance to acquire the lock before this function does - as a result, this function will never block.
Will not block.
Definition at line 606 of file named_rw_lock.cpp.
| void CppCommon::NamedRWLock::LockRead | ( | ) |
| void CppCommon::NamedRWLock::LockWrite | ( | ) |
| const std::string & CppCommon::NamedRWLock::name | ( | ) | const |
Get the read/write lock name.
Definition at line 524 of file named_rw_lock.cpp.
|
delete |
|
delete |
| bool CppCommon::NamedRWLock::TryConvertWriteToRead | ( | ) |
Try to convert write lock to read lock without block.
Will not block.
Definition at line 528 of file named_rw_lock.cpp.
| bool CppCommon::NamedRWLock::TryConvertWriteToReadFor | ( | const Timespan & | timespan | ) |
Try to convert write lock to read lock for the given timespan.
Will block for the given timespan in the worst case.
| timespan | - Timespan to wait for the write lock to read lock conversion |
Definition at line 578 of file named_rw_lock.cpp.
|
inline |
Try to convert write lock to read lock until the given timestamp.
Will block until the given timestamp in the worst case.
| timestamp | - Timestamp to stop wait for the write lock to read lock conversion |
Definition at line 121 of file named_rw_lock.h.
| bool CppCommon::NamedRWLock::TryLockRead | ( | ) |
Try to acquire read lock without block.
Will not block.
Definition at line 526 of file named_rw_lock.cpp.
| bool CppCommon::NamedRWLock::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 530 of file named_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 |
Definition at line 103 of file named_rw_lock.h.
| bool CppCommon::NamedRWLock::TryLockWrite | ( | ) |
Try to acquire write lock without block.
Will not block.
Definition at line 527 of file named_rw_lock.cpp.
| bool CppCommon::NamedRWLock::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 554 of file named_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 |
Definition at line 112 of file named_rw_lock.h.
| void CppCommon::NamedRWLock::UnlockRead | ( | ) |
Release read lock.
Will not block.
Definition at line 604 of file named_rw_lock.cpp.
| void CppCommon::NamedRWLock::UnlockWrite | ( | ) |
Release write lock.
Will not block.
Definition at line 605 of file named_rw_lock.cpp.