Skip to content

Commit 00b2b7f

Browse files
committed
Make sure the Mutex ReentrantLock is never acquired twice
1 parent 4362755 commit 00b2b7f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,20 @@ public static void lockInternal(RubyContext context, ReentrantLock lock, RubyNod
4444

4545
@TruffleBoundary
4646
protected static void lockEvenWithExceptions(ReentrantLock lock, DynamicObject thread, RubyNode currentNode) {
47-
final RubyContext context = currentNode.getContext();
48-
49-
if (lock.isHeldByCurrentThread()) {
50-
throw new RaiseException(context, context.getCoreExceptions().threadErrorRecursiveLocking(currentNode));
51-
}
52-
5347
// We need to re-lock this lock after a Mutex#sleep, no matter what, even if another thread throw us an exception.
5448
// Yet, we also need to allow safepoints to happen otherwise the thread that could unlock could be blocked.
5549
try {
56-
internalLockEvenWithException(lock, currentNode, context);
50+
internalLockEvenWithException(lock, currentNode, currentNode.getContext());
5751
} finally {
5852
Layouts.THREAD.getOwnedLocks(thread).add(lock);
5953
}
6054
}
6155

6256
protected static void internalLockEvenWithException(ReentrantLock lock, RubyNode currentNode, RubyContext context) {
57+
if (lock.isHeldByCurrentThread()) {
58+
throw new RaiseException(context, context.getCoreExceptions().threadErrorRecursiveLocking(currentNode));
59+
}
60+
6361
if (lock.tryLock()) {
6462
return;
6563
}

0 commit comments

Comments
 (0)