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

ruby-changes:35269

From: akr <ko1@a...>
Date: Tue, 2 Sep 2014 20:47:48 +0900 (JST)
Subject: [ruby-changes:35269] akr:r47351 (trunk): * process.c (handle_fork_error): Extracted from retry_fork.

akr	2014-09-02 20:47:35 +0900 (Tue, 02 Sep 2014)

  New Revision: 47351

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

  Log:
    * process.c (handle_fork_error): Extracted from retry_fork.

  Modified files:
    trunk/ChangeLog
    trunk/process.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47350)
+++ ChangeLog	(revision 47351)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Sep  2 19:48:26 2014  Tanaka Akira  <akr@f...>
+
+	* process.c (handle_fork_error): Extracted from retry_fork.
+
 Tue Sep  2 17:02:53 2014  Vit Ondruch  <v.ondruch@t...>
 
 	* tool/rbinstall.rb: fixed error of local installation.
Index: process.c
===================================================================
--- process.c	(revision 47350)
+++ process.c	(revision 47351)
@@ -3173,6 +3173,43 @@ chfunc_protect(VALUE arg) https://github.com/ruby/ruby/blob/trunk/process.c#L3173
 #define O_BINARY 0
 #endif
 
+static int
+handle_fork_error(int *status, int *ep, int *state_p, int *try_gc_p)
+{
+    switch (errno) {
+      case ENOMEM:
+        if ((*try_gc_p)-- > 0 && !rb_during_gc()) {
+            rb_gc();
+            return 0;
+        }
+        break;
+      case EAGAIN:
+#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
+      case EWOULDBLOCK:
+#endif
+        if (!status && !ep) {
+            rb_thread_sleep(1);
+            return 0;
+        }
+        else {
+            rb_protect((VALUE (*)())rb_thread_sleep, 1, state_p);
+            if (status) *status = *state_p;
+            if (!*state_p) return 0;
+        }
+        break;
+    }
+    if (ep) {
+        preserving_errno((close(ep[0]), close(ep[1])));
+    }
+    if (*state_p && !status) rb_jump_tag(*state_p);
+    return -1;
+}
+
+#define prefork() (		\
+	rb_io_flush(rb_stdout), \
+	rb_io_flush(rb_stderr)	\
+	)
+
 /*
  * Forks child process, and returns the process ID in the parent
  * process.
@@ -3206,11 +3243,6 @@ retry_fork(int *status, int *ep, int chf https://github.com/ruby/ruby/blob/trunk/process.c#L3243
     int state = 0;
     int try_gc = 1;
 
-#define prefork() (		\
-	rb_io_flush(rb_stdout), \
-	rb_io_flush(rb_stderr)	\
-	)
-
     while (1) {
         prefork();
         if (!chfunc_is_async_signal_safe)
@@ -3223,33 +3255,8 @@ retry_fork(int *status, int *ep, int chf https://github.com/ruby/ruby/blob/trunk/process.c#L3255
         if (0 < pid) /* fork succeed, parent process */
             return pid;
         /* fork failed */
-	switch (errno) {
-	  case ENOMEM:
-	    if (try_gc-- > 0 && !rb_during_gc()) {
-		rb_gc();
-		continue;
-	    }
-	    break;
-	  case EAGAIN:
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
-	  case EWOULDBLOCK:
-#endif
-	    if (!status && !ep) {
-		rb_thread_sleep(1);
-		continue;
-	    }
-	    else {
-		rb_protect((VALUE (*)())rb_thread_sleep, 1, &state);
-		if (status) *status = state;
-		if (!state) continue;
-	    }
-	    break;
-	}
-	if (ep) {
-	    preserving_errno((close(ep[0]), close(ep[1])));
-	}
-	if (state && !status) rb_jump_tag(state);
-	return -1;
+        if (handle_fork_error(status, ep, &state, &try_gc))
+            return -1;
     }
 }
 

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

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