diff --git a/thread.c b/thread.c index ae80a70682..360807b073 100644 --- a/thread.c +++ b/thread.c @@ -3971,12 +3971,13 @@ ruby_ppoll(struct pollfd *fds, nfds_t nfds, int tmp, tmp2; if (ts->tv_sec > INT_MAX/1000) - timeout_ms = -1; + timeout_ms = INT_MAX; else { tmp = (int)(ts->tv_sec * 1000); - tmp2 = (int)(ts->tv_nsec / (1000 * 1000)); + /* round up 1ns to 1ms to avoid excessive wakeups for <1ms sleep */ + tmp2 = (int)((ts->tv_nsec + 999999L) / (1000L * 1000L)); if (INT_MAX - tmp < tmp2) - timeout_ms = -1; + timeout_ms = INT_MAX; else timeout_ms = (int)(tmp + tmp2); }