Mutex construct that distinguishes between lock for read and lock for write. More...
#include <readWriteMutex.hpp>
Public Types | |
using | AtomicInt = T_AtomicInt |
See ReadWriteMutex. | |
using | ThreadInformation = T_ThreadInformation |
See ReadWriteMutex. | |
Public Member Functions | |
void | lockRead () |
Acquire mutex for read access. | |
void | lockWrite () |
Acquire mutex for write access. | |
ReadWriteMutex () | |
Constructor. | |
void | unlockRead () |
Release mutex that was acquired for read access. | |
void | unlockWrite () |
Release mutex that was acquired for write access. | |
~ReadWriteMutex () | |
Destructor. | |
Mutex construct that distinguishes between lock for read and lock for write.
Since not all shared memory parallel APIs provide such mutexes, this is a custom implementation based on the atomic type.
The custom locking mechanism is annotated for the thread sanitizer so that the synchronization due to this mutex is captured correctly when checking for data races.
The user is responsible for correct pairing of lockForRead, unlockForRead and lockForWrite, unlockForWrite, respectively. Use of the RAII locks LockForRead and LockForWrite is advised.
Recursive locking for read is supported.
T_ThreadInformation | Implementation of ThreadInformationInterface. |
T_AtomicInt | Implementation of AtomicInterface, instantiated with an underlying integer type. |
|
inline |
Acquire mutex for read access.
Waits until there are no writers. Multiple simultaneous acquisitions for reading are allowed.
|
inline |
Acquire mutex for write access.
First writer comes first, as soon as there are no readers. Other writers, if any, wait until the first one is done.