diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-10 14:48:58 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-10 14:48:58 +0000 |
commit | 3385f6a0d45210c45bcc09871075032d82dc814c (patch) | |
tree | 34654e575b5142368c059ee3f0c35fd29868fd5c | |
parent | 779ce6b00ea711f1f6cffaebf2d8a837bb161a69 (diff) | |
download | ruby-3385f6a0d45210c45bcc09871075032d82dc814c.tar.gz |
thread_pthread.c: timer_thread_pipe struct
* thread_pthread.c (timer_thread_pipe): aggregate timer thread
pipe stuff into a struct.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | thread_pthread.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/thread_pthread.c b/thread_pthread.c index ba7aa1ddca..0df64237ce 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1218,9 +1218,14 @@ static int check_signal_thread_list(void) { return 0; } #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) 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) 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 pipes[2]) 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* gvl) 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* gvl) /* 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 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 { |