38#include "atomicInterface.hpp"
39#include "threadInformationInterface.hpp"
41#ifdef __SANITIZE_THREAD__
42 #define ANNOTATE_RWLOCK_CREATE(lock) AnnotateRWLockCreate(__FILE__, __LINE__, (void*)lock)
43 #define ANNOTATE_RWLOCK_DESTROY(lock) AnnotateRWLockDestroy(__FILE__, __LINE__, (void*)lock)
44 #define ANNOTATE_RWLOCK_ACQUIRED(lock, isWrite) AnnotateRWLockAcquired(__FILE__, __LINE__, (void*)lock, isWrite)
45 #define ANNOTATE_RWLOCK_RELEASED(lock, isWrite) AnnotateRWLockReleased(__FILE__, __LINE__, (void*)lock, isWrite)
47extern "C" void AnnotateRWLockCreate(
const char* f,
int l,
void* addr);
48extern "C" void AnnotateRWLockDestroy(
const char* f,
int l,
void* addr);
49extern "C" void AnnotateRWLockAcquired(
const char* f,
int l,
void* addr,
size_t isWrite);
50extern "C" void AnnotateRWLockReleased(
const char* f,
int l,
void* addr,
size_t isWrite);
73 template<
typename T_ThreadInformation,
typename T_AtomicInt>
84#ifdef __SANITIZE_THREAD__
94#ifdef __SANITIZE_THREAD__
99#ifdef __SANITIZE_THREAD__
100 ANNOTATE_RWLOCK_CREATE(&dummy);
106 delete[] nestingDepth;
107#ifdef __SANITIZE_THREAD__
108 ANNOTATE_RWLOCK_DESTROY(&dummy);
121 int const threadId = ThreadInformation::getThreadId();
122 if (nestingDepth[threadId] > 0) {
123 ++nestingDepth[threadId];
129 currentWriters = numWriters;
130 }
while (currentWriters > 0);
134 currentWriters = numWriters;
135 if (currentWriters == 0) {
136 ++nestingDepth[threadId];
143#ifdef __SANITIZE_THREAD__
144 ANNOTATE_RWLOCK_ACQUIRED(&dummy,
false);
150#ifdef __SANITIZE_THREAD__
151 ANNOTATE_RWLOCK_RELEASED(&dummy,
false);
153 int const threadId = ThreadInformation::getThreadId();
154 --nestingDepth[threadId];
155 if (nestingDepth[threadId] == 0) {
170 currentWriters = ++numWriters;
172 if (currentWriters == 1) {
182 currentReaders = numReaders;
183 }
while (currentReaders != 0);
185#ifdef __SANITIZE_THREAD__
186 ANNOTATE_RWLOCK_ACQUIRED(&dummy,
true);
192#ifdef __SANITIZE_THREAD__
193 ANNOTATE_RWLOCK_RELEASED(&dummy,
true);
205 template<
typename T_ReadWriteMutex>
232 template<
typename T_ReadWriteMutex>
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
RAII lock for read. ´
Definition readWriteMutex.hpp:206
LockForRead(ReadWriteMutex &mutex)
Constructor. Acquires lock for read access.
Definition readWriteMutex.hpp:217
~LockForRead()
Destructor. Releases lock for read access.
Definition readWriteMutex.hpp:222
T_ReadWriteMutex ReadWriteMutex
See LockForRead.
Definition readWriteMutex.hpp:208
RAII lock for write.
Definition readWriteMutex.hpp:233
~LockForWrite()
Destructor. Releases lock for write access.
Definition readWriteMutex.hpp:249
LockForWrite(ReadWriteMutex &mutex)
Constructor. Acquires lock for write access.
Definition readWriteMutex.hpp:244
T_ReadWriteMutex ReadWriteMutex
See LockForWrite.
Definition readWriteMutex.hpp:235
Mutex construct that distinguishes between lock for read and lock for write.
Definition readWriteMutex.hpp:74
ReadWriteMutex()
Constructor.
Definition readWriteMutex.hpp:90
T_AtomicInt AtomicInt
See ReadWriteMutex.
Definition readWriteMutex.hpp:77
void lockWrite()
Acquire mutex for write access.
Definition readWriteMutex.hpp:166
void lockRead()
Acquire mutex for read access.
Definition readWriteMutex.hpp:117
~ReadWriteMutex()
Destructor.
Definition readWriteMutex.hpp:105
void unlockWrite()
Release mutex that was acquired for write access.
Definition readWriteMutex.hpp:191
T_ThreadInformation ThreadInformation
See ReadWriteMutex.
Definition readWriteMutex.hpp:76
void unlockRead()
Release mutex that was acquired for read access.
Definition readWriteMutex.hpp:149