From f65ee1e8f1aa6713ff9f7189855ac711af93a9b9 Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 18 Feb 2018 02:12:18 +0000 Subject: [PATCH] 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 --- thread.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/thread.c b/thread.c index 014e15bbaa..da47e7c873 100644 --- a/thread.c +++ b/thread.c @@ -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_except); struct timespec end; + struct timespec *tsp = 0; struct timespec ts #if defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8) = {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(writefds, &orig_write), \ restore_fdset(exceptfds, &orig_except), \ - update_timespec(&ts, &end)) + update_timespec(tsp, &end)) if (timeout) { getclockofday(&end); timespec_add(&end, timespec_for(&ts, timeout)); + tsp = &ts; } #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({ result = native_fd_select(n, readfds, writefds, exceptfds, - timeval_for(timeout, &ts), th); + timeval_for(timeout, tsp), th); if (result < 0) lerrno = errno; }, 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); } while (result < 0 && retryable(errno = lerrno) && - update_timespec(&ts, &end)); + update_timespec(tsp, &end)); if (result < 0) return -1; if (fds.revents & POLLNVAL) {