Skip to content

Commit 4362755

Browse files
committed
Reformat the code to make it clear the condLock is always unlock-ed
* That way, SpotBugs can follow the logic too.
1 parent 4c5e2cd commit 4362755

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/main/java/org/truffleruby/core/mutex/ConditionVariableNodes.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,27 @@ private void waitInternal(DynamicObject conditionVariable, ReentrantLock mutexLo
103103
// If there is an interrupt, it should be consumed by condition.await() and the Ruby Thread sleep status
104104
// must imply being ready to be interrupted by Thread#{run,wakeup}.
105105
condLock.lock();
106-
mutexLock.unlock();
107-
108-
Layouts.CONDITION_VARIABLE
109-
.setWaiters(conditionVariable, Layouts.CONDITION_VARIABLE.getWaiters(conditionVariable) + 1);
110106
try {
111-
awaitSignal(conditionVariable, thread, durationInNanos, condLock, condition, endNanoTime);
112-
} catch (Error | RuntimeException e) {
113-
/*
114-
* Consume a signal if one was waiting. We do this because the error may have
115-
* occurred while we were waiting, or at some point after exiting a safepoint that
116-
* throws an exception and another thread has attempted to signal us. It is valid
117-
* for us to consume this signal because we are still marked as waiting for it.
118-
*/
119-
consumeSignal(conditionVariable);
120-
throw e;
121-
} finally {
107+
mutexLock.unlock();
108+
122109
Layouts.CONDITION_VARIABLE
123-
.setWaiters(conditionVariable, Layouts.CONDITION_VARIABLE.getWaiters(conditionVariable) - 1);
110+
.setWaiters(conditionVariable, Layouts.CONDITION_VARIABLE.getWaiters(conditionVariable) + 1);
111+
try {
112+
awaitSignal(conditionVariable, thread, durationInNanos, condLock, condition, endNanoTime);
113+
} catch (Error | RuntimeException e) {
114+
/*
115+
* Consume a signal if one was waiting. We do this because the error may have
116+
* occurred while we were waiting, or at some point after exiting a safepoint that
117+
* throws an exception and another thread has attempted to signal us. It is valid
118+
* for us to consume this signal because we are still marked as waiting for it.
119+
*/
120+
consumeSignal(conditionVariable);
121+
throw e;
122+
} finally {
123+
Layouts.CONDITION_VARIABLE
124+
.setWaiters(conditionVariable, Layouts.CONDITION_VARIABLE.getWaiters(conditionVariable) - 1);
125+
}
126+
} finally {
124127
condLock.unlock();
125128
MutexOperations.internalLockEvenWithException(mutexLock, this, getContext());
126129
}

0 commit comments

Comments
 (0)