ruby-changes:30494
From: naruse <ko1@a...>
Date: Fri, 16 Aug 2013 02:18:51 +0900 (JST)
Subject: [ruby-changes:30494] naruse:r42573 (trunk): * process.c (rb_clock_gettime): add CLOCK_MONOTONIC support on OS X.
naruse 2013-08-16 02:18:45 +0900 (Fri, 16 Aug 2013) New Revision: 42573 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42573 Log: * process.c (rb_clock_gettime): add CLOCK_MONOTONIC support on OS X. http://developer.apple.com/library/mac/qa/qa1398/_index.html [Feature #8658] Modified files: trunk/ChangeLog trunk/process.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42572) +++ ChangeLog (revision 42573) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Aug 16 02:14:09 2013 NARUSE, Yui <naruse@r...> + + * process.c (rb_clock_gettime): add CLOCK_MONOTONIC support on OS X. + http://developer.apple.com/library/mac/qa/qa1398/_index.html + [Feature #8658] + Fri Aug 16 01:37:43 2013 Tanaka Akira <akr@f...> * bignum.c (bigdivrem_single): Use shift when y is a power of two. Index: process.c =================================================================== --- process.c (revision 42572) +++ process.c (revision 42573) @@ -82,6 +82,10 @@ https://github.com/ruby/ruby/blob/trunk/process.c#L82 #include <grp.h> #endif +#ifdef __APPLE__ +# include <mach/mach_time.h> +#endif + #if defined(HAVE_TIMES) || defined(_WIN32) static VALUE rb_cProcessTms; #endif @@ -6743,6 +6747,23 @@ rb_clock_gettime(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L6747 ts.tv_nsec = 0; goto success; } + +#ifdef __APPLE__ +#define RUBY_MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC ID2SYM(rb_intern("MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC")) + if (clk_id == RUBY_MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC) { + static mach_timebase_info_data_t sTimebaseInfo; + uint64_t t = mach_absolute_time(); + + if ( sTimebaseInfo.denom == 0 ) { + (void) mach_timebase_info(&sTimebaseInfo); + } + + t = t * sTimebaseInfo.numer / sTimebaseInfo.denom; + ts.tv_sec = t / 1000000000; + ts.tv_nsec = t % 1000000000; + goto success; + } +#endif } else { #if defined(HAVE_CLOCK_GETTIME) @@ -7066,6 +7087,8 @@ Init_process(void) https://github.com/ruby/ruby/blob/trunk/process.c#L7087 #endif #ifdef CLOCK_MONOTONIC rb_define_const(rb_mProcess, "CLOCK_MONOTONIC", CLOCKID2NUM(CLOCK_MONOTONIC)); +#elif defined(RUBY_MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC) + rb_define_const(rb_mProcess, "CLOCK_MONOTONIC", RUBY_MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC); #endif #ifdef CLOCK_PROCESS_CPUTIME_ID rb_define_const(rb_mProcess, "CLOCK_PROCESS_CPUTIME_ID", CLOCKID2NUM(CLOCK_PROCESS_CPUTIME_ID)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/