thread.c: stop updating timespec when timeout is unspecified

No need to waste cycles updating timespecs if there's no expiry.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2018-02-18 02:12:18 +00:00
parent e6bf0128ad
commit f65ee1e8f1

View File

@ -3802,6 +3802,7 @@ do_select(int n, rb_fdset_t *const readfds, rb_fdset_t *const writefds,
rb_fdset_t MAYBE_UNUSED(orig_write); rb_fdset_t MAYBE_UNUSED(orig_write);
rb_fdset_t MAYBE_UNUSED(orig_except); rb_fdset_t MAYBE_UNUSED(orig_except);
struct timespec end; struct timespec end;
struct timespec *tsp = 0;
struct timespec ts struct timespec ts
#if defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8) #if defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8)
= {0, 0} = {0, 0}
@ -3813,11 +3814,12 @@ do_select(int n, rb_fdset_t *const readfds, rb_fdset_t *const writefds,
(restore_fdset(readfds, &orig_read), \ (restore_fdset(readfds, &orig_read), \
restore_fdset(writefds, &orig_write), \ restore_fdset(writefds, &orig_write), \
restore_fdset(exceptfds, &orig_except), \ restore_fdset(exceptfds, &orig_except), \
update_timespec(&ts, &end)) update_timespec(tsp, &end))
if (timeout) { if (timeout) {
getclockofday(&end); getclockofday(&end);
timespec_add(&end, timespec_for(&ts, timeout)); timespec_add(&end, timespec_for(&ts, timeout));
tsp = &ts;
} }
#define fd_init_copy(f) \ #define fd_init_copy(f) \
@ -3832,7 +3834,7 @@ do_select(int n, rb_fdset_t *const readfds, rb_fdset_t *const writefds,
BLOCKING_REGION({ BLOCKING_REGION({
result = native_fd_select(n, readfds, writefds, exceptfds, result = native_fd_select(n, readfds, writefds, exceptfds,
timeval_for(timeout, &ts), th); timeval_for(timeout, tsp), th);
if (result < 0) lerrno = errno; if (result < 0) lerrno = errno;
}, ubf_select, th, FALSE); }, ubf_select, th, FALSE);
@ -3974,7 +3976,7 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *timeout)
RUBY_VM_CHECK_INTS_BLOCKING(th->ec); RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
} while (result < 0 && retryable(errno = lerrno) && } while (result < 0 && retryable(errno = lerrno) &&
update_timespec(&ts, &end)); update_timespec(tsp, &end));
if (result < 0) return -1; if (result < 0) return -1;
if (fds.revents & POLLNVAL) { if (fds.revents & POLLNVAL) {