ruby-changes:50344
From: normal <ko1@a...>
Date: Sun, 18 Feb 2018 11:12:28 +0900 (JST)
Subject: [ruby-changes:50344] normal:r62459 (trunk): thread_pthread.c (native_cond_timeout): simplify
normal 2018-02-18 11:12:23 +0900 (Sun, 18 Feb 2018) New Revision: 62459 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62459 Log: 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. Modified files: trunk/thread_pthread.c Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 62458) +++ thread_pthread.c (revision 62459) @@ -365,33 +365,25 @@ native_cond_timedwait(rb_nativethread_co https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L365 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); + timespec_add(&abs, &timeout_rel); - if (timeout.tv_sec < now.tv_sec) - timeout.tv_sec = TIMET_MAX; - - return timeout; + return abs; } #define native_cleanup_push pthread_cleanup_push -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/