Skip to content

Commit f9872de

Browse files
committed
Assert decrements to correct counter value.
1 parent 87e8580 commit f9872de

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

include/opdi/logic/omp/mutexOmpLogic.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,18 @@ void opdi::MutexOmpLogic::decrementReverseFunc(void* dataPtr) {
8282
#endif
8383

8484
// decrement counter
85-
#pragma omp atomic update
86-
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
8797

8898
#if OPDI_OMP_LOGIC_INSTRUMENT
8999
for (auto& instrument : ompLogicInstruments) {
@@ -146,7 +156,7 @@ void opdi::MutexOmpLogic::onMutexAcquired(MutexKind mutexKind, WaitId waitId) {
146156
data->waitId = waitId;
147157

148158
omp_set_lock(&recordings[mutexKind].lock);
149-
data->counter = recordings[mutexKind].counters[waitId]++;
159+
data->counter = recordings[mutexKind].counters[waitId]++; // store value prior to increment
150160
localCounters[mutexKind][waitId] = recordings[mutexKind].counters[waitId]; // remember incremented counter value for the release event
151161
omp_unset_lock(&recordings[mutexKind].lock);
152162

0 commit comments

Comments
 (0)