ruby-changes:19413
From: kosaki <ko1@a...>
Date: Sat, 7 May 2011 01:56:14 +0900 (JST)
Subject: [ruby-changes:19413] Ruby:r31453 (trunk): * thread_pthread.c (get_ts): add monotonic clock capability.
kosaki 2011-05-07 01:56:06 +0900 (Sat, 07 May 2011) New Revision: 31453 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31453 Log: * thread_pthread.c (get_ts): add monotonic clock capability. * thread_pthread.c (rb_thread_create_timer_thread): use monotonic clock if possible. Modified files: trunk/ChangeLog trunk/thread_pthread.c Index: ChangeLog =================================================================== --- ChangeLog (revision 31452) +++ ChangeLog (revision 31453) @@ -1,3 +1,9 @@ +Sat May 7 01:54:21 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * thread_pthread.c (get_ts): add monotonic clock capability. + * thread_pthread.c (rb_thread_create_timer_thread): use monotonic + clock if possible. + Sat May 7 01:43:37 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * thread_pthread.h (rb_thread_cond_t): add clockid field. it's Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 31452) +++ thread_pthread.c (revision 31453) @@ -920,10 +920,29 @@ static struct timespec * get_ts(struct timespec *ts, unsigned long nsec) { + int ret; struct timeval tv; - gettimeofday(&tv, 0); + +#if USE_MONOTONIC_COND + if (timer_thread_cond.clockid == CLOCK_MONOTONIC) { + ret = clock_gettime(CLOCK_MONOTONIC, ts); + if (ret != 0) + rb_sys_fail("clock_gettime(CLOCK_MONOTONIC)"); + goto out; + } +#endif + + if (timer_thread_cond.clockid != CLOCK_REALTIME) + rb_bug("unsupported clockid %d", timer_thread_cond.clockid); + + ret = gettimeofday(&tv, 0); + if (ret != 0) + rb_sys_fail(0); ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec * 1000 + nsec; + ts->tv_nsec = tv.tv_usec * 1000; + + out: + ts->tv_nsec += nsec; if (ts->tv_nsec >= PER_NANO) { ts->tv_sec++; ts->tv_nsec -= PER_NANO; @@ -975,7 +994,7 @@ int err; pthread_attr_init(&attr); - native_cond_initialize(&timer_thread_cond, 0); + native_cond_initialize(&timer_thread_cond, RB_CONDATTR_CLOCK_MONOTONIC); #ifdef PTHREAD_STACK_MIN pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + (THREAD_DEBUG ? BUFSIZ : 0)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/