Skip to content

Commit f807ae5

Browse files
committed
Use InterruptibleFunction for runUntilResultKeepStatus()
1 parent c9f32d2 commit f807ae5

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/main/java/org/truffleruby/core/fiber/FiberManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ public static void waitForInitializationEntered(RubyContext context, RubyFiber f
8282
assert context.getEnv().getContext().isEntered();
8383
final CountDownLatch initializedLatch = fiber.initializedLatch;
8484

85-
context.getThreadManager().runUntilResultKeepStatus(currentNode, CountDownLatch::await, initializedLatch);
85+
context.getThreadManager().runUntilResultKeepStatus(currentNode, latch -> {
86+
latch.await();
87+
return BlockingAction.SUCCESS;
88+
}, initializedLatch);
8689

8790
final Throwable uncaughtException = fiber.uncaughtException;
8891
if (uncaughtException != null) {

src/main/java/org/truffleruby/core/regexp/TruffleRegexpNodes.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,19 +1088,13 @@ protected Object match(
10881088
@TruffleBoundary
10891089
private int runMatch(Matcher matcher, int startPos, int range, boolean onlyMatchAtStart) {
10901090
// Keep status as RUN because MRI has an uninterruptible Regexp engine
1091-
int[] result = new int[1];
10921091
if (onlyMatchAtStart) {
1093-
getContext().getThreadManager().runUntilResultKeepStatus(
1094-
this,
1095-
r -> r[0] = matcher.matchInterruptible(startPos, range, Option.DEFAULT),
1096-
result);
1092+
return getContext().getThreadManager().runUntilResultKeepStatus(this,
1093+
unused -> matcher.matchInterruptible(startPos, range, Option.DEFAULT), null);
10971094
} else {
1098-
getContext().getThreadManager().runUntilResultKeepStatus(
1099-
this,
1100-
r -> r[0] = matcher.searchInterruptible(startPos, range, Option.DEFAULT),
1101-
result);
1095+
return getContext().getThreadManager().runUntilResultKeepStatus(this,
1096+
unused -> matcher.searchInterruptible(startPos, range, Option.DEFAULT), null);
11021097
}
1103-
return result[0];
11041098
}
11051099

11061100
private boolean assertValidRegion(Region region) {

src/main/java/org/truffleruby/core/thread/ThreadManager.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.oracle.truffle.api.TruffleOptions;
2727
import com.oracle.truffle.api.TruffleSafepoint;
2828
import com.oracle.truffle.api.TruffleSafepoint.Interrupter;
29+
import com.oracle.truffle.api.TruffleSafepoint.InterruptibleFunction;
2930
import com.oracle.truffle.api.interop.InteropLibrary;
3031
import com.oracle.truffle.api.object.DynamicObjectLibrary;
3132
import com.oracle.truffle.api.source.SourceSection;
@@ -504,9 +505,9 @@ public interface BlockingAction<T> {
504505
}
505506

506507
@TruffleBoundary
507-
public <T> void runUntilResultKeepStatus(Node currentNode, TruffleSafepoint.Interruptible<T> action, T object) {
508+
public <T, R> R runUntilResultKeepStatus(Node currentNode, InterruptibleFunction<T, R> action, T object) {
508509
assert context.getEnv().getContext().isEntered() : "Use retryWhileInterrupted() when not entered";
509-
TruffleSafepoint.setBlockedThreadInterruptible(currentNode, action, object);
510+
return TruffleSafepoint.setBlockedThreadInterruptibleFunction(currentNode, action, object);
510511
}
511512

512513
public static Object executeBlockingCall(RubyThread thread, Interrupter interrupter, Object executable,
@@ -646,7 +647,10 @@ public void killAndWaitOtherThreads() {
646647
// Wait and join all Java threads we created
647648
for (Thread thread : rubyManagedThreads) {
648649
if (thread != Thread.currentThread()) {
649-
runUntilResultKeepStatus(DummyNode.INSTANCE, Thread::join, thread);
650+
runUntilResultKeepStatus(DummyNode.INSTANCE, t -> {
651+
t.join();
652+
return BlockingAction.SUCCESS;
653+
}, thread);
650654
}
651655
}
652656
}

0 commit comments

Comments
 (0)