Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Process::Waiter with pid in Process.detach #4566

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ private static int rlimitResourceType(Ruby runtime, IRubyObject rtype) {
// MRI: rlimit_resource_name2int
private static int rlimitResourceName2int(String name, int casetype) {
RLIMIT resource;

OUTER: while (true) {
switch (Character.toUpperCase(name.charAt(0))) {
case 'A':
Expand Down Expand Up @@ -1369,9 +1369,9 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block)
}
};

return RubyThread.newInstance(
runtime.getThread(),
IRubyObject.NULL_ARRAY,
return RubyThread.startWaiterThread(
runtime,
pid,
CallBlock.newCallClosure(recv, (RubyModule)recv, Signature.NO_ARGUMENTS, callback, context));
}

Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,14 @@ private static RubyThread startThread(final IRubyObject recv, final IRubyObject[
return rubyThread;
}

protected static RubyThread startWaiterThread(final Ruby runtime, int pid, Block block) {
final IRubyObject waiter = runtime.getClassFromPath("Process::Waiter");
final RubyThread rubyThread = new RubyThread(runtime, (RubyClass) waiter);
rubyThread.op_aset(runtime.newSymbol("pid"), runtime.newFixnum(pid));
rubyThread.callInit(IRubyObject.NULL_ARRAY, block);
return rubyThread;
}

public synchronized void cleanTerminate(IRubyObject result) {
finalResult = result;
}
Expand Down
13 changes: 12 additions & 1 deletion core/src/main/ruby/jruby/kernel/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ class WaitThread < Thread
class << self
private :new
end


def pid
self[:pid]
end
end

class Waiter < Thread
# only created from Java and used for Process.detach right now
class << self
private :new
end

def pid
self[:pid]
end
Expand Down