ruby-changes:66586
From: Nobuyoshi <ko1@a...>
Date: Thu, 24 Jun 2021 17:09:09 +0900 (JST)
Subject: [ruby-changes:66586] 358a357f72 (master): Reduce repeated same code
https://git.ruby-lang.org/ruby.git/commit/?id=358a357f72 From 358a357f727be271a1a59dfbc2ec0bf634261205 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 23 Jun 2021 11:02:44 +0900 Subject: Reduce repeated same code --- thread.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/thread.c b/thread.c index ed77116..2d3a3e1 100644 --- a/thread.c +++ b/thread.c @@ -4242,6 +4242,9 @@ sigwait_timeout(rb_thread_t *th, int sigwait_fd, const rb_hrtime_t *orig, https://github.com/ruby/ruby/blob/trunk/thread.c#L4242 return orig; } +#define sigwait_signals_fd(result, cond, sigwait_fd) \ + (result > 0 && (cond) ? (result--, (sigwait_fd)) : -1) + static VALUE do_select(VALUE p) { @@ -4277,13 +4280,10 @@ do_select(VALUE p) https://github.com/ruby/ruby/blob/trunk/thread.c#L4280 }, 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)) { - result--; - (void)check_signals_nogvl(set->th, set->sigwait_fd); - } - else { - (void)check_signals_nogvl(set->th, -1); - } + int fd = sigwait_signals_fd(result, + rb_fd_isset(set->sigwait_fd, set->rset), + set->sigwait_fd); + (void)check_signals_nogvl(set->th, fd); } RUBY_VM_CHECK_INTS_BLOCKING(set->th->ec); /* may raise */ @@ -4430,12 +4430,8 @@ rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout) https://github.com/ruby/ruby/blob/trunk/thread.c#L4430 }, ubf, wfd.th, TRUE); 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); - } + int fd1 = sigwait_signals_fd(result, fds[1].revents, fds[1].fd); + (void)check_signals_nogvl(wfd.th, fd1); rb_sigwait_fd_put(wfd.th, fds[1].fd); rb_sigwait_fd_migrate(wfd.th->vm); } -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/