fix rb_thread_wait_for_single_fd on non MN case

`rb_thread_wait_for_single_fd(fd)` waits until `fd` is ready.
Without MN it shouldn't use `thread_io_wait_events()` for the
retry checking (alwasy false if MN is not active).
This commit is contained in:
Koichi Sasada 2024-01-09 00:27:40 +09:00
parent 47ff4a1658
commit 41dd15944f

View File

@ -4342,7 +4342,11 @@ rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t *
int int
rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout) rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
{ {
struct pollfd fds[1]; struct pollfd fds[1] = {{
.fd = fd,
.events = (short)events,
.revents = 0,
}};
int result = 0; int result = 0;
nfds_t nfds; nfds_t nfds;
struct waiting_fd wfd; struct waiting_fd wfd;
@ -4354,18 +4358,18 @@ rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
thread_io_setup_wfd(th, fd, &wfd); thread_io_setup_wfd(th, fd, &wfd);
if (timeout == NULL && thread_io_wait_events(th, fd, events, NULL)) {
// fd is readable
state = 0;
fds[0].revents = events;
errno = 0;
}
else {
EC_PUSH_TAG(wfd.th->ec); EC_PUSH_TAG(wfd.th->ec);
if ((state = EC_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
rb_hrtime_t *to, rel, end = 0; rb_hrtime_t *to, rel, end = 0;
struct timeval tv;
RUBY_VM_CHECK_INTS_BLOCKING(wfd.th->ec); RUBY_VM_CHECK_INTS_BLOCKING(wfd.th->ec);
timeout_prepare(&to, &rel, &end, timeout); timeout_prepare(&to, &rel, &end, timeout);
fds[0].fd = fd;
fds[0].events = (short)events;
fds[0].revents = 0;
do { do {
nfds = 1; nfds = 1;
@ -4380,11 +4384,10 @@ rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
}, ubf_select, wfd.th, TRUE); }, ubf_select, wfd.th, TRUE);
RUBY_VM_CHECK_INTS_BLOCKING(wfd.th->ec); RUBY_VM_CHECK_INTS_BLOCKING(wfd.th->ec);
} while (wait_retryable(&result, lerrno, to, end) && } while (wait_retryable(&result, lerrno, to, end));
thread_io_wait_events(th, fd, events, rb_hrtime2timeval(&tv, to)) &&
wait_retryable(&result, lerrno, to, end));
} }
EC_POP_TAG(); EC_POP_TAG();
}
thread_io_wake_pending_closer(&wfd); thread_io_wake_pending_closer(&wfd);