Reduce repeated same code
This commit is contained in:
parent
4c8c3fb230
commit
358a357f72
22
thread.c
22
thread.c
@ -4242,6 +4242,9 @@ sigwait_timeout(rb_thread_t *th, int sigwait_fd, const rb_hrtime_t *orig,
|
||||
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)
|
||||
}, 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)
|
||||
}, 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user