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

ruby-changes:27631

From: kosaki <ko1@a...>
Date: Sun, 10 Mar 2013 13:00:04 +0900 (JST)
Subject: [ruby-changes:27631] kosaki:r39683 (trunk): * thread_pthread.c (rb_thread_create_timer_thread): factor out

kosaki	2013-03-10 12:59:49 +0900 (Sun, 10 Mar 2013)

  New Revision: 39683

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

  Log:
    * thread_pthread.c (rb_thread_create_timer_thread): factor out
      creating communication pipe logic into separate function.
    * thread_pthread.c (setup_communication_pipe): new helper function.
    * thread_pthread.c (set_nonblock): moves a definition before
      setup_communication_pipe.

  Modified files:
    trunk/ChangeLog
    trunk/process.c
    trunk/thread_pthread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39682)
+++ ChangeLog	(revision 39683)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Mar  6 21:42:24 2013  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* thread_pthread.c (rb_thread_create_timer_thread): factor out
+	  creating communication pipe logic into separate function.
+	* thread_pthread.c (setup_communication_pipe): new helper function.
+	* thread_pthread.c (set_nonblock): moves a definition before
+	  setup_communication_pipe.
+
 Sun Mar  3 02:42:29 2013  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* thread_pthread.c (consume_communication_pipe): retry when
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 39682)
+++ thread_pthread.c	(revision 39683)
@@ -1216,6 +1216,52 @@ close_communication_pipe(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1216
     timer_thread_pipe[0] = timer_thread_pipe[1] = -1;
 }
 
+#if USE_SLEEPY_TIMER_THREAD
+static void
+set_nonblock(int fd)
+{
+    int oflags;
+    int err;
+
+    oflags = fcntl(fd, F_GETFL);
+    if (oflags == -1)
+	rb_sys_fail(0);
+    oflags |= O_NONBLOCK;
+    err = fcntl(fd, F_SETFL, oflags);
+    if (err == -1)
+	rb_sys_fail(0);
+}
+#endif
+
+static void
+setup_communication_pipe(void)
+{
+#if USE_SLEEPY_TIMER_THREAD
+    int err;
+
+    /* communication pipe with timer thread and signal handler */
+    if (timer_thread_pipe_owner_process != getpid()) {
+	if (timer_thread_pipe[0] != -1) {
+	    /* close pipe of parent process */
+	    close_communication_pipe();
+	}
+
+	err = rb_cloexec_pipe(timer_thread_pipe);
+	if (err != 0) {
+	    rb_bug_errno("setup_communication_pipe: Failed to create communication pipe for timer thread", errno);
+	}
+	rb_update_max_fd(timer_thread_pipe[0]);
+	rb_update_max_fd(timer_thread_pipe[1]);
+	set_nonblock(timer_thread_pipe[0]);
+	set_nonblock(timer_thread_pipe[1]);
+
+	/* validate pipe on this process */
+	timer_thread_pipe_owner_process = getpid();
+    }
+#endif /* USE_SLEEPY_TIMER_THREAD */
+}
+
+
 /**
  * Let the timer thread sleep a while.
  *
@@ -1319,23 +1365,6 @@ thread_timer(void *p) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1365
 }
 
 static void
-set_nonblock(int fd)
-{
-#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(F_SETFL) && defined(O_NONBLOCK)
-    int oflags;
-    int err;
-
-    oflags = fcntl(fd, F_GETFL);
-    if (oflags == -1)
-	rb_sys_fail(0);
-    oflags |= O_NONBLOCK;
-    err = fcntl(fd, F_SETFL, oflags);
-    if (err == -1)
-	rb_sys_fail(0);
-#endif
-}
-
-static void
 rb_thread_create_timer_thread(void)
 {
     if (!timer_thread_id) {
@@ -1364,27 +1393,7 @@ rb_thread_create_timer_thread(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1393
 # endif
 #endif
 
-#if USE_SLEEPY_TIMER_THREAD
-	/* communication pipe with timer thread and signal handler */
-	if (timer_thread_pipe_owner_process != getpid()) {
-	    if (timer_thread_pipe[0] != -1) {
-		/* close pipe of parent process */
-		close_communication_pipe();
-	    }
-
-	    err = rb_cloexec_pipe(timer_thread_pipe);
-	    if (err != 0) {
-		rb_bug_errno("thread_timer: Failed to create communication pipe for timer thread", errno);
-	    }
-            rb_update_max_fd(timer_thread_pipe[0]);
-            rb_update_max_fd(timer_thread_pipe[1]);
-	    set_nonblock(timer_thread_pipe[0]);
-	    set_nonblock(timer_thread_pipe[1]);
-
-	    /* validate pipe on this process */
-	    timer_thread_pipe_owner_process = getpid();
-	}
-#endif /* USE_SLEEPY_TIMER_THREAD */
+	setup_communication_pipe();
 
 	/* create timer thread */
 	if (timer_thread_id) {
Index: process.c
===================================================================
--- process.c	(revision 39682)
+++ process.c	(revision 39683)
@@ -1080,6 +1080,32 @@ before_exec_non_async_signal_safe(void) https://github.com/ruby/ruby/blob/trunk/process.c#L1080
 }
 
 static void
+setup_communication_pipe(void)
+{
+#if USE_SLEEPY_TIMER_THREAD
+	/* communication pipe with timer thread and signal handler */
+	if (timer_thread_pipe_owner_process != getpid()) {
+	    if (timer_thread_pipe[0] != -1) {
+		/* close pipe of parent process */
+		close_communication_pipe();
+	    }
+
+	    err = rb_cloexec_pipe(timer_thread_pipe);
+	    if (err != 0) {
+		rb_bug_errno("thread_timer: Failed to create communication pipe for timer thread", errno);
+	    }
+            rb_update_max_fd(timer_thread_pipe[0]);
+            rb_update_max_fd(timer_thread_pipe[1]);
+	    set_nonblock(timer_thread_pipe[0]);
+	    set_nonblock(timer_thread_pipe[1]);
+
+	    /* validate pipe on this process */
+	    timer_thread_pipe_owner_process = getpid();
+	}
+#endif /* USE_SLEEPY_TIMER_THREAD */
+}
+
+static void
 before_exec(void)
 {
     before_exec_non_async_signal_safe();

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

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