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

ruby-changes:4844

From: ko1@a...
Date: Fri, 9 May 2008 19:17:29 +0900 (JST)
Subject: [ruby-changes:4844] matz - Ruby:r16338 (trunk): * thread.c (timeofday): use monotonic clock. based on a patch

matz	2008-05-09 19:17:15 +0900 (Fri, 09 May 2008)

  New Revision: 16338

  Modified files:
    trunk/ChangeLog
    trunk/thread.c

  Log:
    * thread.c (timeofday): use monotonic clock.  based on a patch
      from zimbatm <zimbatm@o...> in [ruby-core:16627].

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16338&r2=16337&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/thread.c?r1=16338&r2=16337&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16337)
+++ ChangeLog	(revision 16338)
@@ -1,3 +1,8 @@
+Fri May  9 19:16:00 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* thread.c (timeofday): use monotonic clock.  based on a patch
+	  from zimbatm <zimbatm@o...> in [ruby-core:16627].
+
 Fri May  9 07:47:07 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* cont.c (cont_restore_0): dynamic stack direction code should be
Index: thread.c
===================================================================
--- thread.c	(revision 16337)
+++ thread.c	(revision 16338)
@@ -674,9 +674,18 @@
 static double
 timeofday(void)
 {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
+#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+    struct timespec tp;
+
+    if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
+        return (double)tp.tv_sec + (double)tp.tv_nsec * 1e-9;
+    } else
+#endif
+    {
+        struct timeval tv;
+        gettimeofday(&tv, NULL);
+        return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
+    }
 }
 
 static void

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

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