public ThreadContext getCurrentContext() { return threadService.getCurrentContext(); }
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 void setCritical(boolean critical) { if (critical && !criticalLock.isHeldByCurrentThread()) { acquireCritical(); } else if (!critical && criticalLock.isHeldByCurrentThread()) { releaseCritical(); } }
private static RubyThread adoptThread(final Ruby runtime, final ThreadService service, final RubyClass recv, final Thread thread) { final RubyThread rubyThread = new RubyThread(runtime, recv); rubyThread.threadImpl = new NativeThread(rubyThread, thread); ThreadContext context = service.registerNewThread(rubyThread); service.associateThread(thread, rubyThread); context.preAdoptThread(); // set to default thread group runtime.getDefaultThreadGroup().addDirectly(rubyThread); return rubyThread; }
@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(); } }
public static RubyThread mainThread(IRubyObject receiver) { return receiver.getRuntime().getThreadService().getMainThread(); }
@Override public void run() { javaThread = Thread.currentThread(); ThreadContext context = runtime.getThreadService().registerNewThread(rubyThread); runtime.getThreadService().getMainThread().kill(); } catch (Throwable t) { rubyThread.exceptionRaised(t); } finally { runtime.getThreadService().setCritical(false); rubyThread.dispose();
@Override public void run() { javaThread = Thread.currentThread(); ThreadContext context = runtime.getThreadService().registerNewThread(rubyThread); } catch (MainExitException mee) { runtime.getThreadService().getMainThread().kill(); } catch (Throwable t) { rubyThread.exceptionRaised(t);
getThreadService().disposeCurrentThread(); ProfileData profileData = threadService.getMainThread().getContext().getProfileData(); printProfileData(profileData);
ProfileCollection profileCollection = threadService.getMainThread().getContext().getProfileCollection(); printProfileData(profileCollection); getThreadService().teardown();
private IRubyObject startThread(ThreadContext context, Runnable runnable) throws RaiseException, OutOfMemoryError { final Ruby runtime = context.runtime; try { Thread thread = new Thread(runnable); thread.setDaemon(true); this.file = context.getFile(); this.line = context.getLine(); initThreadName(runtime, thread, file, line); threadImpl = new NativeThread(this, thread); addToCorrectThreadGroup(context); // JRUBY-2380, associate thread early so it shows up in Thread.list right away, in case it doesn't run immediately runtime.getThreadService().associateThread(thread, this); // copy parent thread's interrupt masks interruptMaskStack.addAll(context.getThread().interruptMaskStack); threadImpl.start(); // We yield here to hopefully permit the target thread to schedule // MRI immediately schedules it, so this is close but not exact Thread.yield(); return this; } catch (OutOfMemoryError oome) { if (oome.getMessage().equals("unable to create new native thread")) { throw runtime.newThreadError(oome.getMessage()); } throw oome; } catch (SecurityException ex) { throw runtime.newThreadError(ex.getMessage()); } }
ref = adoptCurrentThread(); context = ref.get(); } else {
this.threadService = new ThreadService(this);
} finally { data.queue.shutdown(); runtime.getThreadService().disposeCurrentThread();
@Override public void run() { javaThread = Thread.currentThread(); RubyThread rubyThread; // spin a bit until this happens; should almost never spin while ((rubyThread = waitThread[0]) == null) { Thread.yield(); } ThreadContext context = runtime.getThreadService().registerNewThread(rubyThread); rubyThread.op_aset( runtime.newSymbol("pid"), runtime.newFixnum(pid)); try { int exitValue = tuple.process.waitFor(); RubyProcess.RubyStatus status = RubyProcess.RubyStatus.newProcessStatus( runtime, exitValue, pid); rubyThread.cleanTerminate(status); } catch (Throwable t) { rubyThread.exceptionRaised(t); } finally { rubyThread.dispose(); } }
public static RubyThread mainThread(IRubyObject receiver) { return receiver.getRuntime().getThreadService().getMainThread(); }
private static RubyThread adoptThread(final Ruby runtime, final ThreadService service, final RubyClass recv, final Thread thread) { final RubyThread rubyThread = new RubyThread(runtime, recv); rubyThread.threadImpl = new NativeThread(rubyThread, thread); ThreadContext context = service.registerNewThread(rubyThread); service.associateThread(thread, rubyThread); context.preAdoptThread(); // set to default thread group runtime.getDefaultThreadGroup().addDirectly(rubyThread); return rubyThread; }
@Override public void run() { javaThread = Thread.currentThread(); ThreadContext context = runtime.getThreadService().registerNewThread(rubyThread); runtime.getThreadService().getMainThread().kill(); } catch (Throwable t) { rubyThread.exceptionRaised(t); } finally { runtime.getThreadService().setCritical(false); rubyThread.dispose();
@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(); } }