@@ -73,11 +73,6 @@ void opdi::MutexOmpLogic::waitReverseFunc(void* dataPtr) {
7373 #endif
7474}
7575
76- void opdi::MutexOmpLogic::waitDeleteFunc (void * dataPtr) {
77- Data* data = static_cast <Data*>(dataPtr);
78- delete data;
79- }
80-
8176void opdi::MutexOmpLogic::decrementReverseFunc (void * dataPtr) {
8277
8378 Data* data = static_cast <Data*>(dataPtr);
@@ -87,8 +82,18 @@ void opdi::MutexOmpLogic::decrementReverseFunc(void* dataPtr) {
8782 #endif
8883
8984 // decrement counter
90- #pragma omp atomic update
91- MutexOmpLogic::evaluationCounters[data->mutexKind ][data->waitId ] -= 1 ;
85+ #ifdef NDEBUG
86+ #pragma omp atomic update
87+ MutexOmpLogic::evaluationCounters[data->mutexKind ][data->waitId ] -= 1 ;
88+ #else
89+ Counter newValue;
90+ #pragma omp atomic capture
91+ {
92+ MutexOmpLogic::evaluationCounters[data->mutexKind ][data->waitId ] -= 1 ;
93+ newValue = MutexOmpLogic::evaluationCounters[data->mutexKind ][data->waitId ];
94+ }
95+ assert (newValue == data->counter );
96+ #endif
9297
9398 #if OPDI_OMP_LOGIC_INSTRUMENT
9499 for (auto & instrument : ompLogicInstruments) {
@@ -97,7 +102,7 @@ void opdi::MutexOmpLogic::decrementReverseFunc(void* dataPtr) {
97102 #endif
98103}
99104
100- void opdi::MutexOmpLogic::decrementDeleteFunc (void * dataPtr) {
105+ void opdi::MutexOmpLogic::deleteFunc (void * dataPtr) {
101106 Data* data = static_cast <Data*>(dataPtr);
102107 delete data;
103108}
@@ -151,7 +156,7 @@ void opdi::MutexOmpLogic::onMutexAcquired(MutexKind mutexKind, WaitId waitId) {
151156 data->waitId = waitId;
152157
153158 omp_set_lock (&recordings[mutexKind].lock );
154- data->counter = recordings[mutexKind].counters [waitId]++;
159+ data->counter = recordings[mutexKind].counters [waitId]++; // store value prior to increment
155160 localCounters[mutexKind][waitId] = recordings[mutexKind].counters [waitId]; // remember incremented counter value for the release event
156161 omp_unset_lock (&recordings[mutexKind].lock );
157162
@@ -165,7 +170,7 @@ void opdi::MutexOmpLogic::onMutexAcquired(MutexKind mutexKind, WaitId waitId) {
165170 Handle* handle = new Handle;
166171 handle->data = static_cast <void *>(data);
167172 handle->reverseFunc = MutexOmpLogic::decrementReverseFunc;
168- handle->deleteFunc = MutexOmpLogic::decrementDeleteFunc ;
173+ handle->deleteFunc = MutexOmpLogic::deleteFunc ;
169174
170175 tool->pushExternalFunction (tool->getThreadLocalTape (), handle);
171176 }
@@ -206,7 +211,7 @@ void opdi::MutexOmpLogic::onMutexReleased(MutexKind mutexKind, WaitId waitId) {
206211 Handle* handle = new Handle;
207212 handle->data = static_cast <void *>(data);
208213 handle->reverseFunc = MutexOmpLogic::waitReverseFunc;
209- handle->deleteFunc = MutexOmpLogic::waitDeleteFunc ;
214+ handle->deleteFunc = MutexOmpLogic::deleteFunc ;
210215
211216 tool->pushExternalFunction (tool->getThreadLocalTape (), handle);
212217 }
0 commit comments