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: 27b38db0309a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 856857255e58
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Apr 19, 2017

  1. Return Process::Waiter with pid in Process.detach

    This adds a `pid` method to threads returned by `Process.detach`,
    as described in the open3.rb documentation. The thread is a
    `Process::Waiter` to be consistent with standard Ruby.
    
    Before:
    
    ```
    >> JRUBY_VERSION
    => "9.1.4.0"
    >> pid = Process.spawn('sleep 10')
    => 58487
    >> thr = Process.detach(_)
    => #<Thread:0x45752059@(irb):3 run>
    >> thr.pid
    NoMethodError: undefined method `pid' for #<Thread:0x45752059@(irb):3 dead>
    ```
    
    After:
    
    ```
    >> JRUBY_VERSION
    => "9.1.9.0-SNAPSHOT"
    >> pid = Process.spawn('sleep 10')
    => 59018
    >> thr = Process.detach(_)
    => #<Process::Waiter:0x5acf93bb@(irb):3 run>
    >> thr.pid
    => 59018
    ```
    davishmcclurg committed Apr 19, 2017
    Copy the full SHA
    8f591fd View commit details
  2. Merge pull request #4566 from davishmcclurg/davishmcclurg/wait-thread…

    …-pid
    
    Return Process::Waiter with pid in Process.detach
    headius authored Apr 19, 2017
    Copy the full SHA
    8568572 View commit details
Showing with 24 additions and 5 deletions.
  1. +4 −4 core/src/main/java/org/jruby/RubyProcess.java
  2. +8 −0 core/src/main/java/org/jruby/RubyThread.java
  3. +12 −1 core/src/main/ruby/jruby/kernel/process.rb
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyProcess.java
Original file line number Diff line number Diff line change
@@ -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':
@@ -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));
}

8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 12 additions & 1 deletion core/src/main/ruby/jruby/kernel/process.rb
Original file line number Diff line number Diff line change
@@ -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