aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--process.c23
2 files changed, 29 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 36cf4d3109..d7c63b6f81 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/process.c b/process.c
index 7600b53ba6..da09b15194 100644
--- a/process.c
+++ b/process.c
@@ -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));