Skip to content

Commit

Permalink
[Truffle] Simplify logic in ThreadManager.runOnce.
Browse files Browse the repository at this point in the history
* We do not need the global lock to poll anymore.
  • Loading branch information
eregon committed Feb 11, 2015
1 parent f641527 commit b2446b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Expand Up @@ -59,6 +59,10 @@ public void poll() {
poll(true);
}

public void pollWithoutGlobalLock() {
poll(false);
}

private void poll(boolean holdsGlobalLock) {
try {
assumption.check();
Expand Down
Expand Up @@ -112,21 +112,20 @@ public <T> T runUntilResult(BlockingActionWithoutGlobalLock<T> action) {
@CompilerDirectives.TruffleBoundary
public <T> T runOnce(BlockingActionWithoutGlobalLock<T> action) {
T result = null;

final RubyThread runningThread = leaveGlobalLock();
runningThread.setStatus(Status.SLEEP);

try {
try {
result = action.block();
} finally {
runningThread.setStatus(Status.RUN);
// We need to enter the global lock before anything else!
enterGlobalLock(runningThread);
}
runningThread.setStatus(Status.SLEEP);
result = action.block();
} catch (InterruptedException e) {
// We were interrupted, possibly by the SafepointManager.
context.getSafepointManager().poll();
context.getSafepointManager().pollWithoutGlobalLock();
} finally {
runningThread.setStatus(Status.RUN);
enterGlobalLock(runningThread);
}

return result;
}

Expand Down

0 comments on commit b2446b7

Please sign in to comment.