[前][次][番号順一覧][スレッド一覧]

ruby-changes:30684

From: akr <ko1@a...>
Date: Mon, 2 Sep 2013 00:09:13 +0900 (JST)
Subject: [ruby-changes:30684] akr:r42763 (trunk): * process.c (get_mach_timebase_info): Extracted from rb_clock_gettime.

akr	2013-09-02 00:09:06 +0900 (Mon, 02 Sep 2013)

  New Revision: 42763

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42763

  Log:
    * process.c (get_mach_timebase_info): Extracted from rb_clock_gettime.
      (rb_clock_gettime): Use get_mach_timebase_info.
      (rb_clock_getres): Support MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC.

  Modified files:
    trunk/ChangeLog
    trunk/process.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42762)
+++ ChangeLog	(revision 42763)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Sep  2 00:08:08 2013  Tanaka Akira  <akr@f...>
+
+	* process.c (get_mach_timebase_info): Extracted from rb_clock_gettime.
+	  (rb_clock_gettime): Use get_mach_timebase_info.
+	  (rb_clock_getres): Support MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC.
+
 Sun Sep  1 23:30:47 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (GMP_BIG2STR_DIGITS): New constant.
Index: process.c
===================================================================
--- process.c	(revision 42762)
+++ process.c	(revision 42763)
@@ -6851,6 +6851,20 @@ make_clock_result(struct timetick *ttp, https://github.com/ruby/ruby/blob/trunk/process.c#L6851
         rb_raise(rb_eArgError, "unexpected unit: %"PRIsVALUE, unit);
 }
 
+#ifdef __APPLE__
+static mach_timebase_info_data_t *
+get_mach_timebase_info(void)
+{
+    static mach_timebase_info_data_t sTimebaseInfo;
+
+    if ( sTimebaseInfo.denom == 0 ) {
+        (void) mach_timebase_info(&sTimebaseInfo);
+    }
+
+    return &sTimebaseInfo;
+}
+#endif
+
 /*
  *  call-seq:
  *     Process.clock_gettime(clock_id [, unit])   -> number
@@ -7069,17 +7083,12 @@ rb_clock_gettime(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L7083
 #ifdef __APPLE__
 #define RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC ID2SYM(rb_intern("MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC"))
         if (clk_id == RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC) {
-	    static mach_timebase_info_data_t sTimebaseInfo;
-	    uint64_t t = mach_absolute_time();
-
-	    if ( sTimebaseInfo.denom == 0 ) {
-		(void) mach_timebase_info(&sTimebaseInfo);
-	    }
-
+	    mach_timebase_info_data_t *info = get_mach_timebase_info();
+            uint64_t t = mach_absolute_time();
             tt.count = (int32_t)(t % 1000000000);
             tt.giga_count = t / 1000000000;
-            numerators[num_numerators++] = sTimebaseInfo.numer;
-            denominators[num_denominators++] = sTimebaseInfo.denom;
+            numerators[num_numerators++] = info->numer;
+            denominators[num_denominators++] = info->denom;
             denominators[num_denominators++] = 1000000000;
             goto success;
         }
@@ -7205,7 +7214,15 @@ rb_clock_getres(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L7214
 #endif
 
 #ifdef RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC
-        /* not yet */
+        if (clk_id == RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC) {
+	    mach_timebase_info_data_t *info = get_mach_timebase_info();
+            tt.count = 1;
+            tt.giga_count = 0;
+            numerators[num_numerators++] = info->numer;
+            denominators[num_denominators++] = info->denom;
+            denominators[num_denominators++] = 1000000000;
+            goto success;
+        }
 #endif
     }
     else {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]