ruby-changes:59281
From: Eric <ko1@a...>
Date: Tue, 17 Dec 2019 04:00:40 +0900 (JST)
Subject: [ruby-changes:59281] b12bc3b046 (master): thread.c: avoid needless read after select|ppoll
https://git.ruby-lang.org/ruby.git/commit/?id=b12bc3b046 From b12bc3b0461f7331db6e27865fa7a8ef29a0f652 Mon Sep 17 00:00:00 2001 From: Eric Wong <normal@r...> Date: Mon, 16 Dec 2019 18:28:44 +0000 Subject: thread.c: avoid needless read after select|ppoll We do not need to issue pipe|eventfd read(2) syscall unless select, ppoll|poll declares the FD needs reading. diff --git a/thread.c b/thread.c index 80f6f78..17bc1e7 100644 --- a/thread.c +++ b/thread.c @@ -4000,9 +4000,12 @@ do_select(VALUE p) https://github.com/ruby/ruby/blob/trunk/thread.c#L4000 }, set->sigwait_fd >= 0 ? ubf_sigwait : ubf_select, set->th, TRUE); if (set->sigwait_fd >= 0) { - if (result > 0 && rb_fd_isset(set->sigwait_fd, set->rset)) + if (result > 0 && rb_fd_isset(set->sigwait_fd, set->rset)) { result--; - (void)check_signals_nogvl(set->th, set->sigwait_fd); + (void)check_signals_nogvl(set->th, set->sigwait_fd); + } else { + (void)check_signals_nogvl(set->th, -1); + } } RUBY_VM_CHECK_INTS_BLOCKING(set->th->ec); /* may raise */ @@ -4177,8 +4180,10 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *timeout) https://github.com/ruby/ruby/blob/trunk/thread.c#L4180 if (fds[1].fd >= 0) { if (result > 0 && fds[1].revents) { result--; + (void)check_signals_nogvl(wfd.th, fds[1].fd); + } else { + (void)check_signals_nogvl(wfd.th, -1); } - (void)check_signals_nogvl(wfd.th, fds[1].fd); rb_sigwait_fd_put(wfd.th, fds[1].fd); rb_sigwait_fd_migrate(wfd.th->vm); } @@ -4394,7 +4399,7 @@ static int https://github.com/ruby/ruby/blob/trunk/thread.c#L4399 check_signals_nogvl(rb_thread_t *th, int sigwait_fd) { rb_vm_t *vm = GET_VM(); /* th may be 0 */ - int ret = consume_communication_pipe(sigwait_fd); + int ret = sigwait_fd >= 0 ? consume_communication_pipe(sigwait_fd) : FALSE; ubf_wakeup_all_threads(); ruby_sigchld_handler(vm); if (rb_signal_buff_size()) { -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/