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

ruby-changes:33826

From: nobu <ko1@a...>
Date: Sat, 10 May 2014 23:49:06 +0900 (JST)
Subject: [ruby-changes:33826] nobu:r45907 (trunk): thread_pthread.c: timer_thread_pipe struct

nobu	2014-05-10 23:48:58 +0900 (Sat, 10 May 2014)

  New Revision: 45907

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

  Log:
    thread_pthread.c: timer_thread_pipe struct
    
    * thread_pthread.c (timer_thread_pipe): aggregate timer thread
      pipe stuff into a struct.

  Modified files:
    trunk/thread_pthread.c
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 45906)
+++ thread_pthread.c	(revision 45907)
@@ -1218,9 +1218,14 @@ static int check_signal_thread_list(void https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1218
 #define TIME_QUANTUM_USEC (100 * 1000)
 
 #if USE_SLEEPY_TIMER_THREAD
-static int timer_thread_pipe[2] = {-1, -1};
-static int timer_thread_pipe_low[2] = {-1, -1}; /* low priority */
-static int timer_thread_pipe_owner_process;
+static struct {
+    int normal[2];
+    int low[2];
+    int owner_process;
+} timer_thread_pipe = {
+    {-1, -1},
+    {-1, -1}, /* low priority */
+};
 
 /* only use signal-safe system calls here */
 static void
@@ -1229,7 +1234,7 @@ rb_thread_wakeup_timer_thread_fd(int fd) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1234
     ssize_t result;
 
     /* already opened */
-    if (timer_thread_pipe_owner_process == getpid()) {
+    if (timer_thread_pipe.owner_process == getpid()) {
 	const char *buff = "!";
       retry:
 	if ((result = write(fd, buff, 1)) <= 0) {
@@ -1254,13 +1259,13 @@ rb_thread_wakeup_timer_thread_fd(int fd) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1259
 void
 rb_thread_wakeup_timer_thread(void)
 {
-    rb_thread_wakeup_timer_thread_fd(timer_thread_pipe[1]);
+    rb_thread_wakeup_timer_thread_fd(timer_thread_pipe.normal[1]);
 }
 
 static void
 rb_thread_wakeup_timer_thread_low(void)
 {
-    rb_thread_wakeup_timer_thread_fd(timer_thread_pipe_low[1]);
+    rb_thread_wakeup_timer_thread_fd(timer_thread_pipe.low[1]);
 }
 
 /* VM-dependent API is not available for this function */
@@ -1341,15 +1346,15 @@ setup_communication_pipe_internal(int pi https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1346
 static void
 setup_communication_pipe(void)
 {
-    if (timer_thread_pipe_owner_process == getpid()) {
+    if (timer_thread_pipe.owner_process == getpid()) {
 	/* already set up. */
 	return;
     }
-    setup_communication_pipe_internal(timer_thread_pipe);
-    setup_communication_pipe_internal(timer_thread_pipe_low);
+    setup_communication_pipe_internal(timer_thread_pipe.normal);
+    setup_communication_pipe_internal(timer_thread_pipe.low);
 
     /* validate pipe on this process */
-    timer_thread_pipe_owner_process = getpid();
+    timer_thread_pipe.owner_process = getpid();
 }
 
 /**
@@ -1365,9 +1370,9 @@ timer_thread_sleep(rb_global_vm_lock_t* https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1370
     int need_polling;
     struct pollfd pollfds[2];
 
-    pollfds[0].fd = timer_thread_pipe[0];
+    pollfds[0].fd = timer_thread_pipe.normal[0];
     pollfds[0].events = POLLIN;
-    pollfds[1].fd = timer_thread_pipe_low[0];
+    pollfds[1].fd = timer_thread_pipe.low[0];
     pollfds[1].events = POLLIN;
 
     need_polling = check_signal_thread_list();
@@ -1385,8 +1390,8 @@ timer_thread_sleep(rb_global_vm_lock_t* https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1390
 	/* maybe timeout */
     }
     else if (result > 0) {
-	consume_communication_pipe(timer_thread_pipe[0]);
-	consume_communication_pipe(timer_thread_pipe_low[0]);
+	consume_communication_pipe(timer_thread_pipe.normal[0]);
+	consume_communication_pipe(timer_thread_pipe.low[0]);
     }
     else { /* result < 0 */
 	int e = errno;
@@ -1598,10 +1603,10 @@ int https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1603
 rb_reserved_fd_p(int fd)
 {
 #if USE_SLEEPY_TIMER_THREAD
-    if (fd == timer_thread_pipe[0]     ||
-	fd == timer_thread_pipe[1]     ||
-	fd == timer_thread_pipe_low[0] ||
-	fd == timer_thread_pipe_low[1]) {
+    if (fd == timer_thread_pipe.normal[0] ||
+	fd == timer_thread_pipe.normal[1] ||
+	fd == timer_thread_pipe.low[0] ||
+	fd == timer_thread_pipe.low[1]) {
 	return 1;
     }
     else {

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

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