summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-18 02:12:23 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-18 02:12:23 +0000
commit8f47542d5847a1515e6a266812e6ace807b2dd44 (patch)
tree747c5a17d0bf8db0a558cbfefe5cbe08d4515a39 /thread_pthread.c
parentf65ee1e8f1aa6713ff9f7189855ac711af93a9b9 (diff)
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
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c18
1 files changed, 5 insertions, 13 deletions
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