1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* process.c (rb_clock_gettime): add CLOCK_MONOTONIC support on OS X.

http://developer.apple.com/library/mac/qa/qa1398/_index.html
  [Feature #8658]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2013-08-15 17:18:45 +00:00
parent 6df786c79f
commit b26f8003c3
2 changed files with 29 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Fri Aug 16 02:14:09 2013 NARUSE, Yui <naruse@ruby-lang.org>
* 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@fsij.org>
* bignum.c (bigdivrem_single): Use shift when y is a power of two.

View file

@ -82,6 +82,10 @@
#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)
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)
#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));