public BlockingQueue<IRubyObject> getQueueSafe() { BlockingQueue<IRubyObject> queue = this.queue; checkShutdown(); return queue; }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new ThreadFiber(runtime, klazz); } });
public IRubyObject pop(ThreadContext context) { return pop(context, true); }
public static void initRootFiber(ThreadContext context, RubyThread currentThread) { Ruby runtime = context.runtime; ThreadFiber rootFiber = new ThreadFiber(runtime, runtime.getFiber()); rootFiber.data = new FiberData(new FiberQueue(runtime), currentThread, rootFiber); rootFiber.thread = currentThread; context.setRootFiber(rootFiber); }
@JRubyMethod(visibility = Visibility.PRIVATE) public IRubyObject initialize(ThreadContext context, Block block) { Ruby runtime = context.runtime; if (!block.isGiven()) throw runtime.newArgumentError("tried to create Proc object without block"); data = new FiberData(new FiberQueue(runtime), context.getFiberCurrentThread(), this); FiberData currentFiberData = context.getFiber().data; thread = createThread(runtime, data, currentFiberData.queue, block); return context.nil; }
public static void initRootFiber(ThreadContext context) { Ruby runtime = context.runtime; ThreadFiber rootFiber = new ThreadFiber(runtime, runtime.getClass("Fiber")); // FIXME: getFiber() assert runtime.getClass("SizedQueue") != null : "SizedQueue has not been loaded"; rootFiber.data = new FiberData(new SizedQueue(runtime, runtime.getClass("SizedQueue")), null, rootFiber); rootFiber.thread = context.getThread(); context.setRootFiber(rootFiber); }
private static IRubyObject exchangeWithFiber(ThreadContext context, FiberData currentFiberData, FiberData targetFiberData, IRubyObject val) { // At this point we consider ourselves "in" the resume, so we need to enforce exception-propagation // rules for both the push (to wake up fiber) and pop (to wait for fiber). Failure to do this can // cause interrupts destined for the fiber to be caught after the fiber is running but before the // resuming thread has started waiting for it, leaving the fiber to run rather than receiving the // interrupt, and the parent thread propagates the error. // Note: these need to be separate try/catches because of the while loop. try { targetFiberData.queue.push(context, new IRubyObject[] {val}); } catch (RaiseException re) { handleExceptionDuringExchange(context, currentFiberData, targetFiberData, re); } while (true) { try { IRubyObject result = currentFiberData.queue.pop(context); return result == NEVER ? context.nil : result; } catch (RaiseException re) { handleExceptionDuringExchange(context, currentFiberData, targetFiberData, re); } } }
@JRubyMethod(meta = true) public static IRubyObject yield(ThreadContext context, IRubyObject recv, IRubyObject value) { Ruby runtime = context.runtime; FiberData currentFiberData = context.getFiber().data; if (currentFiberData.parent == null) throw runtime.newFiberError("can't yield from root fiber"); if (currentFiberData.prev == null) throw runtime.newFiberError("BUG: yield occurred with null previous fiber. Report this at http://bugs.jruby.org"); if (currentFiberData.queue.isShutdown()) throw runtime.newFiberError("dead fiber yielded"); FiberData prevFiberData = currentFiberData.prev.data; return exchangeWithFiber(context, currentFiberData, prevFiberData, value); }
@JRubyMethod(meta = true) public static IRubyObject yield(ThreadContext context, IRubyObject recv) { return yield(context, recv, context.nil); }
final boolean alive() { RubyThread thread = this.thread; if (thread == null || !thread.isAlive() || data.queue.isShutdown()) { return false; } return true; }
public static void initRootFiber(ThreadContext context, RubyThread currentThread) { Ruby runtime = context.runtime; ThreadFiber rootFiber = new ThreadFiber(runtime, runtime.getFiber()); rootFiber.data = new FiberData(new FiberQueue(runtime), currentThread, rootFiber); rootFiber.thread = currentThread; context.setRootFiber(rootFiber); }
@JRubyMethod(visibility = Visibility.PRIVATE) public IRubyObject initialize(ThreadContext context, Block block) { Ruby runtime = context.runtime; if (!block.isGiven()) throw runtime.newArgumentError("tried to create Proc object without block"); data = new FiberData(new FiberQueue(runtime), context.getFiberCurrentThread(), this); FiberData currentFiberData = context.getFiber().data; thread = createThread(runtime, data, currentFiberData.queue, block); return context.nil; }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new ThreadFiber(runtime, klazz); } });
private static IRubyObject exchangeWithFiber(ThreadContext context, FiberData currentFiberData, FiberData targetFiberData, IRubyObject val) { // At this point we consider ourselves "in" the resume, so we need to enforce exception-propagation // rules for both the push (to wake up fiber) and pop (to wait for fiber). Failure to do this can // cause interrupts destined for the fiber to be caught after the fiber is running but before the // resuming thread has started waiting for it, leaving the fiber to run rather than receiving the // interrupt, and the parent thread propagates the error. // Note: these need to be separate try/catches because of the while loop. try { targetFiberData.queue.push(context, new IRubyObject[] {val}); } catch (RaiseException re) { handleExceptionDuringExchange(context, currentFiberData, targetFiberData, re); } while (true) { try { IRubyObject result = currentFiberData.queue.pop(context); return result == NEVER ? context.nil : result; } catch (RaiseException re) { handleExceptionDuringExchange(context, currentFiberData, targetFiberData, re); } } }
@JRubyMethod(meta = true) public static IRubyObject yield(ThreadContext context, IRubyObject recv) { return yield(context, recv, context.nil); }
public BlockingQueue<IRubyObject> getQueueSafe() { BlockingQueue<IRubyObject> queue = this.queue; checkShutdown(); return queue; }
public IRubyObject pop(ThreadContext context) { return pop(context, true); }
final boolean alive() { RubyThread thread = this.thread; if (thread == null || !thread.isAlive() || data.queue.isShutdown()) { return false; } return true; }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new ThreadFiber(runtime, klazz); } });
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new ThreadFiber(runtime, klazz); } });