2727
2828#include " testBase.hpp"
2929
30+ #ifdef __SANITIZE_THREAD__
31+ #define ANNOTATE_RWLOCK_CREATE (lock ) AnnotateRWLockCreate(__FILE__, __LINE__, (void *)lock)
32+ #define ANNOTATE_RWLOCK_DESTROY (lock ) AnnotateRWLockDestroy(__FILE__, __LINE__, (void *)lock)
33+ #define ANNOTATE_RWLOCK_ACQUIRED (lock, isWrite ) AnnotateRWLockAcquired(__FILE__, __LINE__, (void *)lock, isWrite)
34+ #define ANNOTATE_RWLOCK_RELEASED (lock, isWrite ) AnnotateRWLockReleased(__FILE__, __LINE__, (void *)lock, isWrite)
35+
36+ extern " C" void AnnotateRWLockCreate (const char * f, int l, void * addr);
37+ extern " C" void AnnotateRWLockDestroy (const char * f, int l, void * addr);
38+ extern " C" void AnnotateRWLockAcquired (const char * f, int l, void * addr, size_t isWrite);
39+ extern " C" void AnnotateRWLockReleased (const char * f, int l, void * addr, size_t isWrite);
40+ #endif
41+
3042template <typename _Case>
3143struct TestCustomMutex : public TestBase <4 , 1 , 3 , TestCustomMutex<_Case>> {
3244 public:
@@ -37,8 +49,27 @@ struct TestCustomMutex : public TestBase<4, 1, 3, TestCustomMutex<_Case>> {
3749 private:
3850 int status;
3951
52+ #ifdef __SANITIZE_THREAD__
53+ int dummy;
54+ #endif
55+
4056 public:
41- CustomMutex () : status(0 ) {}
57+ CustomMutex () : status(0 )
58+ #ifdef __SANITIZE_THREAD__
59+ , dummy(0 )
60+ #endif
61+ {
62+
63+ #ifdef __SANITIZE_THREAD__
64+ ANNOTATE_RWLOCK_CREATE (&dummy);
65+ #endif
66+ }
67+
68+ ~CustomMutex () {
69+ #ifdef __SANITIZE_THREAD__
70+ ANNOTATE_RWLOCK_DESTROY (&dummy);
71+ #endif
72+ }
4273
4374 void lock () {
4475 int localStatus;
@@ -69,16 +100,26 @@ struct TestCustomMutex : public TestBase<4, 1, 3, TestCustomMutex<_Case>> {
69100 #endif
70101 --status;
71102 }
103+
104+ #ifdef __SANITIZE_THREAD__
105+ ANNOTATE_RWLOCK_ACQUIRED (&dummy, true );
106+ #endif
107+
72108 #ifdef _OPENMP
73109 opdi::logic->onMutexAcquired (opdi::LogicInterface::MutexKind::Custom, reinterpret_cast <opdi::LogicInterface::WaitId>(&status));
74110 #endif
75111 }
76112
77113 void unlock () {
114+ #ifdef __SANITIZE_THREAD__
115+ ANNOTATE_RWLOCK_RELEASED (&dummy, true );
116+ #endif
117+
78118 #ifdef _OPENMP
79119 #pragma omp atomic update
80120 #endif
81121 --status;
122+
82123 #ifdef _OPENMP
83124 opdi::logic->onMutexReleased (opdi::LogicInterface::MutexKind::Custom, reinterpret_cast <opdi::LogicInterface::WaitId>(&status));
84125 #endif
0 commit comments