public String dumpThreads(Gather gather) { Ruby ruby = this.ruby.get(); RubyThread[] thrs = ruby.getThreadService().getActiveRubyThreads(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("All threads known to Ruby instance " + ruby.hashCode()); pw.println(); for (RubyThread th : thrs) { dumpThread(ruby, th, gather, pw); } return sw.toString(); }
public static RubyThread adopt(IRubyObject recv, Thread t) { final Ruby runtime = recv.getRuntime(); return adoptThread(runtime, runtime.getThreadService(), (RubyClass) recv, t); }
public void run() { nativeThread = Thread.currentThread(); try { runnable.run(); } finally { rubyThread.getRuntime().getThreadService().dissociateThread(future); nativeThread = null; } } });
@JRubyMethod(meta = true) public static IRubyObject exit(IRubyObject receiver, Block block) { RubyThread rubyThread = receiver.getRuntime().getThreadService().getCurrentContext().getThread(); synchronized (rubyThread) { rubyThread.status.set(Status.ABORTING); // FIXME: This was not checking for non-null before, but maybe it should rubyThread.mail.set(null); receiver.getRuntime().getThreadService().setCritical(false); throw new ThreadKill(); } }
/** * Creates a byte array Iterator backed by the given Ruby Enumerable. * * @param body the backing Enumerable. */ public JRubyRackBodyIterator(IRubyObject body) { this.body = body; this.threadContext = body.getRuntime().getThreadService().getCurrentContext(); this.enumerator = (RubyEnumerator) body.callMethod(threadContext, "to_enum"); }
@JRubyMethod(meta = true) public static RubyArray list(IRubyObject recv) { Ruby runtime = recv.getRuntime(); RubyThread[] activeThreads = runtime.getThreadService().getActiveRubyThreads(); return RubyArray.newArrayMayCopy(runtime, activeThreads); }
@JRubyMethod(name = "critical=", required = 1, meta = true, compat = CompatVersion.RUBY1_8) public static IRubyObject critical_set(IRubyObject receiver, IRubyObject value) { receiver.getRuntime().getThreadService().setCritical(value.isTrue()); return value; }
private static RubyThread adoptThread(final IRubyObject recv, Thread t, Block block) { final Ruby runtime = recv.getRuntime(); final RubyThread rubyThread = new RubyThread(runtime, (RubyClass) recv); rubyThread.threadImpl = new NativeThread(rubyThread, t); ThreadContext context = runtime.getThreadService().registerNewThread(rubyThread); runtime.getThreadService().associateThread(t, rubyThread); context.preAdoptThread(); // set to default thread group runtime.getDefaultThreadGroup().addDirectly(rubyThread); return rubyThread; }
@JRubyMethod(name = "critical=", required = 1, meta = true, compat = CompatVersion.RUBY1_8) public static IRubyObject critical_set(IRubyObject receiver, IRubyObject value) { receiver.getRuntime().getThreadService().setCritical(value.isTrue()); return value; }
@JRubyMethod(name = {"kill", "exit", "terminate"}) public IRubyObject kill() { Ruby runtime = getRuntime(); // need to reexamine this RubyThread currentThread = runtime.getCurrentContext().getThread(); if (currentThread == runtime.getThreadService().getMainThread()) { // rb_exit to hard exit process...not quite right for us } status.set(Status.ABORTING); return genericKill(runtime, currentThread); }
public void setRubyProperty(String propertyName, IRubyObject arg) { ThreadContext threadContext = runtime.getThreadService().getCurrentContext(); if (propertyName.startsWith("@")) { rubyNode.getInstanceVariables().setInstanceVariable(propertyName, arg); } else { if (arg == null) { rubyNode.callMethod(threadContext, propertyName + "=", runtime.getNil()); } else { rubyNode.callMethod(threadContext, propertyName + "=", arg); } } }
public void setRubyProperty(String propertyName, IRubyObject arg) { ThreadContext threadContext = runtime.getThreadService().getCurrentContext(); if (propertyName.startsWith("@")) { rubyNode.getInstanceVariables().setInstanceVariable(propertyName, arg); } else { if (arg == null) { rubyNode.callMethod(threadContext, propertyName + "=", runtime.getNil()); } else { rubyNode.callMethod(threadContext, propertyName + "=", arg); } } }
@JRubyMethod(name = {"kill", "exit", "terminate"}) public IRubyObject kill() { Ruby runtime = getRuntime(); // need to reexamine this RubyThread currentThread = runtime.getCurrentContext().getThread(); if (currentThread == runtime.getThreadService().getMainThread()) { // rb_exit to hard exit process...not quite right for us } status.set(Status.ABORTING); return genericKill(runtime, currentThread); }
@JRubyMethod(meta = true) public static IRubyObject exit(IRubyObject receiver, Block block) { RubyThread rubyThread = receiver.getRuntime().getThreadService().getCurrentContext().getThread(); return rubyThread.kill(); }
@JRubyMethod(meta = true) public static IRubyObject exit(IRubyObject receiver, Block block) { RubyThread rubyThread = receiver.getRuntime().getThreadService().getCurrentContext().getThread(); return rubyThread.kill(); }
@JRubyMethod(name = "critical", meta = true, compat = CompatVersion.RUBY1_8) public static IRubyObject critical(IRubyObject receiver) { return receiver.getRuntime().newBoolean(receiver.getRuntime().getThreadService().getCritical()); }
@JRubyMethod(name = "pass", meta = true) public static IRubyObject pass(IRubyObject recv) { Ruby runtime = recv.getRuntime(); ThreadService ts = runtime.getThreadService(); boolean critical = ts.getCritical(); ts.setCritical(false); Thread.yield(); ts.setCritical(critical); return recv.getRuntime().getNil(); }
@JRubyMethod(name = "list", meta = true) public static RubyArray list(IRubyObject recv) { RubyThread[] activeThreads = recv.getRuntime().getThreadService().getActiveRubyThreads(); return recv.getRuntime().newArrayNoCopy(activeThreads); }
@JRubyMethod(name = "exclusive", meta = true, compat = CompatVersion.RUBY1_8) public static IRubyObject exclusive(ThreadContext context, IRubyObject receiver, Block block) { ThreadService service = context.runtime.getThreadService(); boolean old = service.getCritical(); try { service.setCritical(true); return block.yield(receiver.getRuntime().getCurrentContext(), (IRubyObject) null); } finally { service.setCritical(old); } }
@JRubyMethod(name = {"kill", "exit", "terminate"}) public IRubyObject kill() { // need to reexamine this RubyThread currentThread = getRuntime().getCurrentContext().getThread(); // If the killee thread is the same as the killer thread, just die if (currentThread == this) throwThreadKill(); debug(this, "trying to kill"); currentThread.pollThreadEvents(); getRuntime().getThreadService().deliverEvent(new ThreadService.Event(currentThread, this, ThreadService.Event.Type.KILL)); debug(this, "succeeded with kill"); return this; }