Skip to content

Commit

Permalink
Return to interruptible lock acquisition in Mutex.
Browse files Browse the repository at this point in the history
Fixes jruby#5476.

This reverts the original change from jruby#4261 that disabled lock
interrupts, and uses Task logic from RubyThread to handle the
interrupting properly.
  • Loading branch information
headius committed Apr 9, 2019
1 parent 2c0b886 commit f1c7836
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions core/src/main/java/org/jruby/ext/thread/Mutex.java
Expand Up @@ -94,12 +94,28 @@ public IRubyObject lock(ThreadContext context) {

// try locking without sleep status to avoid looking like blocking
if (!thread.tryLock(lock)) {
// failed to acquire, proceed to sleep and block
try {
thread.enterSleep();
thread.lock(lock);
context.getThread().enterSleep();
try {
checkRelocking(context);
context.getThread().executeTask(context, lock, new RubyThread.Task<ReentrantLock, Object>() {
@Override
public Object run(ThreadContext context, ReentrantLock reentrantLock) throws InterruptedException {
reentrantLock.lockInterruptibly();
return reentrantLock;
}

@Override
public void wakeup(RubyThread thread, ReentrantLock reentrantLock) {
thread.getNativeThread().interrupt();
}
});
} catch (InterruptedException ex) {
context.pollThreadEvents();
throw context.runtime.newConcurrencyError("interrupted waiting for mutex");
}
} finally {
thread.exitSleep();
context.getThread().exitSleep();
}
}

Expand Down

0 comments on commit f1c7836

Please sign in to comment.