CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::ReadWriteMutex< T_ThreadInformation, T_AtomicInt > Struct Template Reference

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.
 

Detailed Description

template<typename T_ThreadInformation, typename T_AtomicInt>
struct codi::ReadWriteMutex< T_ThreadInformation, T_AtomicInt >

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.

Template Parameters
T_ThreadInformationImplementation of ThreadInformationInterface.
T_AtomicIntImplementation of AtomicInterface, instantiated with an underlying integer type.

Member Function Documentation

◆ lockRead()

template<typename T_ThreadInformation , typename T_AtomicInt >
void codi::ReadWriteMutex< T_ThreadInformation, T_AtomicInt >::lockRead ( )
inline

Acquire mutex for read access.

Waits until there are no writers. Multiple simultaneous acquisitions for reading are allowed.

◆ lockWrite()

template<typename T_ThreadInformation , typename T_AtomicInt >
void codi::ReadWriteMutex< T_ThreadInformation, T_AtomicInt >::lockWrite ( )
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.


The documentation for this struct was generated from the following file: