|
5 | 5 | import org.jruby.RubyClass;
|
6 | 6 | import org.jruby.RubyModule;
|
7 | 7 | import org.jruby.RubyObject;
|
| 8 | +import org.jruby.RubyThread; |
8 | 9 | import org.jruby.anno.JRubyClass;
|
9 | 10 | import org.jruby.anno.JRubyMethod;
|
10 | 11 | import org.jruby.runtime.Block;
|
@@ -96,6 +97,14 @@ public void load(Ruby runtime, boolean wrap) throws IOException {
|
96 | 97 |
|
97 | 98 | defineClass(runtime, synchronizationModule, "AbstractLockableObject", "JRubyLockableObject",
|
98 | 99 | JRubyLockableObject.class, JRUBY_LOCKABLE_OBJECT_ALLOCATOR);
|
| 100 | + |
| 101 | + defineClass(runtime, synchronizationModule, "Object", "JRuby", |
| 102 | + JRuby.class, new ObjectAllocator() { |
| 103 | + @Override |
| 104 | + public IRubyObject allocate(Ruby runtime, RubyClass klazz) { |
| 105 | + return new JRuby(runtime, klazz); |
| 106 | + } |
| 107 | + }); |
99 | 108 | }
|
100 | 109 |
|
101 | 110 | private RubyClass defineClass(
|
@@ -267,4 +276,29 @@ public IRubyObject nsBroadcast(ThreadContext context) {
|
267 | 276 | return this;
|
268 | 277 | }
|
269 | 278 | }
|
| 279 | + |
| 280 | + @JRubyClass(name = "JRuby") |
| 281 | + public static class JRuby extends RubyObject { |
| 282 | + public JRuby(Ruby runtime, RubyClass metaClass) { |
| 283 | + super(runtime, metaClass); |
| 284 | + } |
| 285 | + |
| 286 | + @JRubyMethod(name = "sleep_interruptibly", visibility = Visibility.PUBLIC, module = true) |
| 287 | + public static IRubyObject sleepInterruptibly(ThreadContext context, IRubyObject receiver, Block block) { |
| 288 | + try { |
| 289 | + return context.getThread().executeTask(context, block, |
| 290 | + new RubyThread.Task<Block, IRubyObject>() { |
| 291 | + public IRubyObject run(ThreadContext context, Block block1) throws InterruptedException { |
| 292 | + return block1.call(context); |
| 293 | + } |
| 294 | + |
| 295 | + public void wakeup(RubyThread thread, Block block1) { |
| 296 | + thread.getNativeThread().interrupt(); |
| 297 | + } |
| 298 | + }); |
| 299 | + } catch (InterruptedException e) { |
| 300 | + throw context.runtime.newThreadError("interrupted in Concurrent::Synchronization::JRuby.sleep_interruptibly"); |
| 301 | + } |
| 302 | + } |
| 303 | + } |
270 | 304 | }
|
0 commit comments