Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8e7bbc0c23a1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cf239351bf65
Choose a head ref
  • 5 commits
  • 1 file changed
  • 1 contributor

Commits on Dec 3, 2015

  1. Copy the full SHA
    c1f7c66 View commit details
  2. Copy the full SHA
    2377b3c View commit details
  3. Copy the full SHA
    8a25977 View commit details
  4. Copy the full SHA
    881aa99 View commit details
  5. Copy the full SHA
    cf23935 View commit details
Showing with 31 additions and 24 deletions.
  1. +31 −24 core/src/main/java/org/jruby/RubyThread.java
55 changes: 31 additions & 24 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -169,7 +169,7 @@ public static enum Status {
private final AtomicReference<Status> status = new AtomicReference<Status>(Status.RUN);

/** Mail slot for cross-thread events */
private final Queue<IRubyObject> pendingInterruptQueue = new ConcurrentLinkedQueue();
private final Queue<IRubyObject> pendingInterruptQueue = new ConcurrentLinkedQueue<>();

/** A function to use to unblock this thread, if possible */
private volatile Unblocker unblockFunc;
@@ -210,14 +210,13 @@ public static enum Status {
protected RubyThread(Ruby runtime, RubyClass type) {
super(runtime, type);

finalResult = runtime.getNil();
errorInfo = runtime.getNil();
finalResult = errorInfo = runtime.getNil();
}

public RubyThread(Ruby runtime, RubyClass klass, Runnable runnable) {
this(runtime, klass);

startWith(runnable);
startThread(runtime.getCurrentContext(), runnable);
}

private void executeInterrupts(ThreadContext context, boolean blockingTiming) {
@@ -546,23 +545,18 @@ private static RubyThread adoptThread(final IRubyObject recv, Thread t, Block bl

@JRubyMethod(rest = true, visibility = PRIVATE)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
Ruby runtime = getRuntime();
if (!block.isGiven()) throw runtime.newThreadError("must be called with a block");
if (threadImpl != null) throw runtime.newThreadError("already initialized thread");

RubyRunnable runnable = new RubyRunnable(this, args, block);
if (!block.isGiven()) throw context.runtime.newThreadError("must be called with a block");
if (threadImpl != null) throw context.runtime.newThreadError("already initialized thread");

return startWith(runnable);
return startThread(context, new RubyRunnable(this, args, block));
}

private IRubyObject startWith(Runnable runnable) throws RaiseException, OutOfMemoryError {
Ruby runtime = getRuntime();
ThreadContext context = runtime.getCurrentContext();

private IRubyObject startThread(ThreadContext context, Runnable runnable) throws RaiseException, OutOfMemoryError {
final Ruby runtime = context.runtime;
try {
Thread thread = new Thread(runnable);
thread.setDaemon(true);
thread.setName("Ruby-" + runtime.getRuntimeNumber() + "-" + thread.getName() + ": " + context.getFile() + ":" + (context.getLine() + 1));
setThreadName(runtime, thread, context.getFile(), context.getLine());
threadImpl = new NativeThread(this, thread);

addToCorrectThreadGroup(context);
@@ -577,16 +571,29 @@ private IRubyObject startWith(Runnable runnable) throws RaiseException, OutOfMem
Thread.yield();

return this;
} catch (OutOfMemoryError oome) {
}
catch (OutOfMemoryError oome) {
if (oome.getMessage().equals("unable to create new native thread")) {
throw runtime.newThreadError(oome.getMessage());
}
throw oome;
} catch (SecurityException ex) {
}
catch (SecurityException ex) {
throw runtime.newThreadError(ex.getMessage());
}
}

private static void setThreadName(final Ruby runtime, final Thread thread,
final String file, final int line) {
final StringBuilder name = new StringBuilder(24);
name.append("Ruby-").append(runtime.getRuntimeNumber());
name.append('-').append(thread.getName());
if ( file != null ) {
name.append(':').append(' ').append(file).append(':').append(line + 1);
}
thread.setName(name.toString());
}

private static RubyThread startThread(final IRubyObject recv, final IRubyObject[] args, boolean callInit, Block block) {
RubyThread rubyThread = new RubyThread(recv.getRuntime(), (RubyClass) recv);

@@ -695,13 +702,12 @@ public IRubyObject pending_interrupt_p(ThreadContext context, IRubyObject[] args
}

@JRubyMethod(name = "name=", required = 1)
public IRubyObject setName(ThreadContext context, IRubyObject name) {
this.threadName = name;
return threadName;
public IRubyObject setName(IRubyObject name) {
return this.threadName = name;
}

@JRubyMethod(name = "name")
public IRubyObject getName(ThreadContext context) {
public IRubyObject getName() {
return this.threadName;
}

@@ -1018,11 +1024,12 @@ public synchronized IRubyObject inspect() {
// FIXME: There's some code duplication here with RubyObject#inspect
StringBuilder part = new StringBuilder();
String cname = getMetaClass().getRealClass().getName();
part.append("#<").append(cname).append(":");
part.append("#<").append(cname).append(':');
part.append(identityString());
if (threadName != null) {
final IRubyObject name = getName(); // thread.name
if (name != null && ! name.isNil()) {
part.append('@');
part.append(threadName.asJavaString());
part.append(name.asJavaString());
}
part.append(' ');
part.append(status.toString().toLowerCase());