Skip to content

Commit

Permalink
* process.c (rb_detach_process): store detached process ID in the
Browse files Browse the repository at this point in the history
  thread local storage.  moved from lib/open3.rb.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jun 20, 2008
1 parent 79bb49b commit a54cbe6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Fri Jun 20 12:39:55 2008 Nobuyoshi Nakada <[email protected]>

* process.c (rb_detach_process): store detached process ID in the
thread local storage. moved from lib/open3.rb.

Fri Jun 20 11:57:46 2008 Yukihiro Matsumoto <[email protected]>

* string.c (rb_str_sub_bang): should preserve replacement points
Expand Down
1 change: 0 additions & 1 deletion lib/open3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def popen3(*cmd)

pid = spawn(*cmd, STDIN=>pw[0], STDOUT=>pr[1], STDERR=>pe[1])
wait_thr = Process.detach(pid)
wait_thr[:pid] = pid
pw[0].close
pr[1].close
pe[1].close
Expand Down
19 changes: 18 additions & 1 deletion process.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,20 @@ proc_waitall(void)
return result;
}

static inline ID
id_pid(void)
{
ID pid;
CONST_ID(pid, "pid");
return pid;
}

static VALUE
detach_process_pid(VALUE thread)
{
return rb_thread_local_aref(thread, id_pid());
}

static VALUE
detach_process_watcher(void *arg)
{
Expand All @@ -900,7 +914,10 @@ detach_process_watcher(void *arg)
VALUE
rb_detach_process(rb_pid_t pid)
{
return rb_thread_create(detach_process_watcher, (void*)(VALUE)pid);
VALUE watcher = rb_thread_create(detach_process_watcher, (void*)(VALUE)pid);
rb_thread_local_aset(watcher, id_pid(), PIDT2NUM(pid));
rb_define_singleton_method(watcher, "pid", detach_process_pid, 0);
return watcher;
}


Expand Down

0 comments on commit a54cbe6

Please sign in to comment.