From 8f47542d5847a1515e6a266812e6ace807b2dd44 Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 18 Feb 2018 02:12:23 +0000 Subject: thread_pthread.c (native_cond_timeout): simplify Rely on getclockofday for CLOCK_MONOTONIC, avoid needless variables, and rely on overflow protection from timespec_add instead of coding our own. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_pthread.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'thread_pthread.c') diff --git a/thread_pthread.c b/thread_pthread.c index d36c149483..e138884a92 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -365,33 +365,25 @@ native_cond_timedwait(rb_nativethread_cond_t *cond, pthread_mutex_t *mutex, cons static struct timespec native_cond_timeout(rb_nativethread_cond_t *cond, struct timespec timeout_rel) { - struct timespec timeout; - struct timespec now; + struct timespec abs; #if USE_MONOTONIC_COND if (cond->clockid == CLOCK_MONOTONIC) { - int ret = clock_gettime(cond->clockid, &now); - if (ret != 0) - rb_sys_fail("clock_gettime()"); + getclockofday(&abs); goto out; } if (cond->clockid != CLOCK_REALTIME) rb_bug("unsupported clockid %"PRIdVALUE, (SIGNED_VALUE)cond->clockid); #endif - rb_timespec_now(&now); + rb_timespec_now(&abs); #if USE_MONOTONIC_COND out: #endif - timeout.tv_sec = now.tv_sec; - timeout.tv_nsec = now.tv_nsec; - timespec_add(&timeout, &timeout_rel); - - if (timeout.tv_sec < now.tv_sec) - timeout.tv_sec = TIMET_MAX; + timespec_add(&abs, &timeout_rel); - return timeout; + return abs; } #define native_cleanup_push pthread_cleanup_push -- cgit v1.2.3