summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/thread.c b/thread.c
index 72cb69b720..8a1e090160 100644
--- a/thread.c
+++ b/thread.c
@@ -994,10 +994,17 @@ sleep_timeval(rb_thread_t *th, struct timeval tv, int spurious_check)
enum rb_thread_status prev_status = th->status;
getclockofday(&to);
- to.tv_sec += tv.tv_sec;
+ if (TIMET_MAX - tv.tv_sec < to.tv_sec)
+ to.tv_sec = TIMET_MAX;
+ else
+ to.tv_sec += tv.tv_sec;
if ((to.tv_usec += tv.tv_usec) >= 1000000) {
- to.tv_sec++;
- to.tv_usec -= 1000000;
+ if (to.tv_sec == TIMET_MAX)
+ to.tv_usec = 999999;
+ else {
+ to.tv_sec++;
+ to.tv_usec -= 1000000;
+ }
}
th->status = THREAD_STOPPED;