Skip to content

Commit

Permalink
Remove forgotten remnants of pre-2.0 critical section logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Aug 28, 2018
1 parent 1999234 commit 4a2dbb1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 57 deletions.
41 changes: 10 additions & 31 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -858,20 +858,10 @@ public static RubyThread main(IRubyObject recv) {
}

@JRubyMethod(meta = true)
public static IRubyObject pass(IRubyObject recv) {
Ruby runtime = recv.getRuntime();
ThreadService ts = runtime.getThreadService();
boolean critical = ts.getCritical();

ts.setCritical(false);
public static IRubyObject pass(ThreadContext context, IRubyObject recv) {
Thread.yield();

try {
Thread.yield();
} finally {
ts.setCritical(critical);
}

return runtime.getNil();
return context.nil;
}

@JRubyMethod(meta = true)
Expand Down Expand Up @@ -1070,21 +1060,6 @@ public IRubyObject join(ThreadContext context, IRubyObject[] args) {
try {
currentThread.enterSleep();

if (runtime.getThreadService().getCritical()) {
// If the target thread is sleeping or stopped, wake it
synchronized (this) {
notify();
}

// interrupt the target thread in case it's blocking or waiting
// WARNING: We no longer interrupt the target thread, since this usually means
// interrupting IO and with NIO that means the channel is no longer usable.
// We either need a new way to handle waking a target thread that's waiting
// on IO, or we need to accept that we can't wake such threads and must wait
// for them to complete their operation.
//threadImpl.interrupt();
}

final long timeToWait = Math.min(timeoutMillis, 200);

// We need this loop in order to be able to "unblock" the
Expand Down Expand Up @@ -1210,9 +1185,6 @@ public static IRubyObject stop(ThreadContext context, IRubyObject receiver) {
rubyThread.pollThreadEvents(context);
Status oldStatus = rubyThread.status.get();
try {
// attempt to decriticalize all if we're the critical thread
receiver.getRuntime().getThreadService().setCritical(false);

rubyThread.status.set(Status.SLEEP);
rubyThread.wait();
} catch (InterruptedException ie) {
Expand Down Expand Up @@ -2239,4 +2211,11 @@ public IRubyObject backtrace_locations(ThreadContext context, IRubyObject[] args
return null; // not reached
}
}

@Deprecated
public static IRubyObject pass(IRubyObject recv) {
Ruby runtime = recv.getRuntime();

return pass(runtime.getCurrentContext(), recv);
}
}
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/ext/timeout/Timeout.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ public static IRubyObject timeout(final ThreadContext context, IRubyObject recv,

final Ruby runtime = context.runtime;

// No timeout in critical section
if (runtime.getThreadService().getCritical()) {
return raiseBecauseCritical(context);
}

final RubyThread currentThread = context.getThread();
final AtomicBoolean latch = new AtomicBoolean(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public void run() {
} catch (Throwable t) {
rubyThread.exceptionRaised(t);
} finally {
runtime.getThreadService().setCritical(false);
rubyThread.dispose();

// restore context classloader, in case we're using a thread pool
Expand Down
44 changes: 24 additions & 20 deletions core/src/main/java/org/jruby/internal/runtime/ThreadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,6 @@ public synchronized void unregisterThread(RubyThread thread) {
localContext.set(null);
}

public void setCritical(boolean critical) {
if (critical && !criticalLock.isHeldByCurrentThread()) {
acquireCritical();
} else if (!critical && criticalLock.isHeldByCurrentThread()) {
releaseCritical();
}
}

private void acquireCritical() {
criticalLock.lock();
}

private void releaseCritical() {
criticalLock.unlock();
}

public boolean getCritical() {
return criticalLock.isHeldByCurrentThread();
}

public long incrementAndGetThreadCount() {
return threadCount.incrementAndGet();
}
Expand Down Expand Up @@ -375,4 +355,28 @@ public static Event wakeup(RubyThread sender, RubyThread target, Type type) {
return new Event(sender.toString() + " sent KILL to " + target, type);
}
}

@Deprecated
public void setCritical(boolean critical) {
if (critical && !criticalLock.isHeldByCurrentThread()) {
acquireCritical();
} else if (!critical && criticalLock.isHeldByCurrentThread()) {
releaseCritical();
}
}

@Deprecated
private void acquireCritical() {
criticalLock.lock();
}

@Deprecated
private void releaseCritical() {
criticalLock.unlock();
}

@Deprecated
public boolean getCritical() {
return criticalLock.isHeldByCurrentThread();
}
}

0 comments on commit 4a2dbb1

Please sign in to comment.