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

ruby-changes:39712

From: nobu <ko1@a...>
Date: Tue, 8 Sep 2015 16:15:24 +0900 (JST)
Subject: [ruby-changes:39712] nobu:r51793 (trunk): process.c: keep GVL if WNOHANG

nobu	2015-09-08 16:15:09 +0900 (Tue, 08 Sep 2015)

  New Revision: 51793

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51793

  Log:
    process.c: keep GVL if WNOHANG
    
    * process.c (rb_waitpid): do not release GVL when WNOHANG is set,
      it should return immediately without blocking.

  Modified files:
    trunk/process.c
Index: process.c
===================================================================
--- process.c	(revision 51792)
+++ process.c	(revision 51793)
@@ -846,20 +846,23 @@ struct waitpid_arg { https://github.com/ruby/ruby/blob/trunk/process.c#L846
     int *st;
 };
 
-static void *
-rb_waitpid_blocking(void *data)
+static rb_pid_t
+do_waitpid(rb_pid_t pid, int *st, int flags)
 {
-    rb_pid_t result;
-    struct waitpid_arg *arg = data;
-
 #if defined HAVE_WAITPID
-    result = waitpid(arg->pid, arg->st, arg->flags);
+    return waitpid(pid, st, flags);
 #elif defined HAVE_WAIT4
-    result = wait4(arg->pid, arg->st, arg->flags, NULL);
+    return wait4(pid, st, flags, NULL);
 #else
 #  error waitpid or wait4 is required.
 #endif
+}
 
+static void *
+rb_waitpid_blocking(void *data)
+{
+    struct waitpid_arg *arg = data;
+    rb_pid_t result = do_waitpid(arg->pid, arg->st, arg->flags);
     return (void *)(VALUE)result;
 }
 
@@ -881,10 +884,15 @@ rb_waitpid(rb_pid_t pid, int *st, int fl https://github.com/ruby/ruby/blob/trunk/process.c#L884
 {
     rb_pid_t result;
 
-    while ((result = do_waitpid_nonblocking(pid, st, flags)) < 0 &&
-	   (errno == EINTR)) {
-	rb_thread_t *th = GET_THREAD();
-	RUBY_VM_CHECK_INTS(th);
+    if (flags & WNOHANG) {
+	result = do_waitpid(pid, st, flags);
+    }
+    else {
+	while ((result = do_waitpid_nonblocking(pid, st, flags)) < 0 &&
+	       (errno == EINTR)) {
+	    rb_thread_t *th = GET_THREAD();
+	    RUBY_VM_CHECK_INTS(th);
+	}
     }
     if (result > 0) {
 	rb_last_status_set(*st, result);

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

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