summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorEric Wong <normal@ruby-lang.org>2019-12-16 18:28:44 (GMT)
committerEric Wong <normal@ruby-lang.org>2019-12-16 18:31:08 (GMT)
commitb12bc3b0461f7331db6e27865fa7a8ef29a0f652 (patch)
tree8f78d17c0f9d2ce0edc6bdc070d7d84ec4e48fed /thread.c
parentbba6386d9568123a7c76693e3a5fa5e33562a640 (diff)
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.
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c13
1 files changed, 9 insertions, 4 deletions
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)
}, 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)
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
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()) {