mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
f65ee1e8f1
commit
8f47542d58
1 changed files with 5 additions and 13 deletions
|
@ -365,33 +365,25 @@ native_cond_timedwait(rb_nativethread_cond_t *cond, pthread_mutex_t *mutex, cons
|
||||||
static struct timespec
|
static struct timespec
|
||||||
native_cond_timeout(rb_nativethread_cond_t *cond, struct timespec timeout_rel)
|
native_cond_timeout(rb_nativethread_cond_t *cond, struct timespec timeout_rel)
|
||||||
{
|
{
|
||||||
struct timespec timeout;
|
struct timespec abs;
|
||||||
struct timespec now;
|
|
||||||
|
|
||||||
#if USE_MONOTONIC_COND
|
#if USE_MONOTONIC_COND
|
||||||
if (cond->clockid == CLOCK_MONOTONIC) {
|
if (cond->clockid == CLOCK_MONOTONIC) {
|
||||||
int ret = clock_gettime(cond->clockid, &now);
|
getclockofday(&abs);
|
||||||
if (ret != 0)
|
|
||||||
rb_sys_fail("clock_gettime()");
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cond->clockid != CLOCK_REALTIME)
|
if (cond->clockid != CLOCK_REALTIME)
|
||||||
rb_bug("unsupported clockid %"PRIdVALUE, (SIGNED_VALUE)cond->clockid);
|
rb_bug("unsupported clockid %"PRIdVALUE, (SIGNED_VALUE)cond->clockid);
|
||||||
#endif
|
#endif
|
||||||
rb_timespec_now(&now);
|
rb_timespec_now(&abs);
|
||||||
|
|
||||||
#if USE_MONOTONIC_COND
|
#if USE_MONOTONIC_COND
|
||||||
out:
|
out:
|
||||||
#endif
|
#endif
|
||||||
timeout.tv_sec = now.tv_sec;
|
timespec_add(&abs, &timeout_rel);
|
||||||
timeout.tv_nsec = now.tv_nsec;
|
|
||||||
timespec_add(&timeout, &timeout_rel);
|
|
||||||
|
|
||||||
if (timeout.tv_sec < now.tv_sec)
|
return abs;
|
||||||
timeout.tv_sec = TIMET_MAX;
|
|
||||||
|
|
||||||
return timeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define native_cleanup_push pthread_cleanup_push
|
#define native_cleanup_push pthread_cleanup_push
|
||||||
|
|
Loading…
Reference in a new issue