Skip to content

Commit 842ae0a

Browse files
committed
Restore RubyThread.wait_timeout used by concurrent_ruby
1 parent fa1305f commit 842ae0a

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

core/src/main/java/org/jruby/RubyThread.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,31 @@ public interface Task<Data, Return> extends Unblocker<Data> {
17411741
public void wakeup(RubyThread thread, Data data);
17421742
}
17431743

1744+
// Deprecated but still used by wait_timeout below
1745+
@Deprecated(since = "10.1.0.0")
1746+
public static final class SleepTask implements BlockingTask {
1747+
private final Object object;
1748+
private final long millis;
1749+
private final int nanos;
1750+
public SleepTask(Object object, long millis, int nanos) {
1751+
this.object = object;
1752+
this.millis = millis;
1753+
this.nanos = nanos;
1754+
}
1755+
@Override
1756+
public void run() throws InterruptedException {
1757+
synchronized (object) {
1758+
object.wait(millis, nanos);
1759+
}
1760+
}
1761+
@Override
1762+
public void wakeup() {
1763+
synchronized (object) {
1764+
object.notify();
1765+
}
1766+
}
1767+
}
1768+
17441769
/**
17451770
* A Task for sleeping.
17461771
*
@@ -2434,6 +2459,25 @@ public void afterBlockingCall() {
24342459
pollThreadEvents();
24352460
}
24362461

2462+
// Deprecated but still used by concurrent_ruby
2463+
@Deprecated(since = "10.1.0.0")
2464+
public boolean wait_timeout(IRubyObject o, Double timeout) throws InterruptedException {
2465+
if ( timeout != null ) {
2466+
long delay_ns = (long)(timeout.doubleValue() * 1000000000.0);
2467+
long start_ns = System.nanoTime();
2468+
if (delay_ns > 0) {
2469+
long delay_ms = delay_ns / 1000000;
2470+
int delay_ns_remainder = (int)( delay_ns % 1000000 );
2471+
executeBlockingTask(new SleepTask(o, delay_ms, delay_ns_remainder));
2472+
}
2473+
long end_ns = System.nanoTime();
2474+
return ( end_ns - start_ns ) <= delay_ns;
2475+
} else {
2476+
executeBlockingTask(new SleepTask(o, 0, 0));
2477+
return true;
2478+
}
2479+
}
2480+
24372481
public RubyThreadGroup getThreadGroup() {
24382482
return threadGroup;
24392483
}

0 commit comments

Comments
 (0)