[前][次][番号順一覧][スレッド一覧]

ruby-changes:5961

From: nobu <ko1@a...>
Date: Fri, 20 Jun 2008 12:40:24 +0900 (JST)
Subject: [ruby-changes:5961] Ruby:r17469 (trunk): * process.c (rb_detach_process): store detached process ID in the

nobu	2008-06-20 12:40:02 +0900 (Fri, 20 Jun 2008)

  New Revision: 17469

  Modified files:
    trunk/ChangeLog
    trunk/lib/open3.rb
    trunk/process.c

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


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=17469&r2=17468&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/open3.rb?r1=17469&r2=17468&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/process.c?r1=17469&r2=17468&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 17468)
+++ ChangeLog	(revision 17469)
@@ -1,3 +1,8 @@
+Fri Jun 20 12:39:55 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <matz@r...>
 
 	* string.c (rb_str_sub_bang): should preserve replacement points
Index: lib/open3.rb
===================================================================
--- lib/open3.rb	(revision 17468)
+++ lib/open3.rb	(revision 17469)
@@ -66,7 +66,6 @@
 
     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
Index: process.c
===================================================================
--- process.c	(revision 17468)
+++ process.c	(revision 17469)
@@ -885,7 +885,21 @@
     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)
 {
     rb_pid_t cpid, pid = (rb_pid_t)(VALUE)arg;
@@ -900,7 +914,10 @@
 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;
 }
 
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]