This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: FYI: System.nanoTime


Tom Tromey wrote:
"Cédric" == Cédric Berger <cedric@berger.to> writes:

Cédric> Why do you use CLOCK_REALTIME? it represents the time Cédric> from the epoch, but nanoTime() javadoc atate that Cédric> nanoTime() value should be used for measuring elapsed Cédric> time and is unrelated to wall-clock time.

What do you think of the appended?

I've not tested it, but by reading it, it looks perfect to me.


Thanks,
Cedric


Tom


Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* posix.cc (_Jv_platform_nanotime): Look for CLOCK_MONOTONIC and
	CLOCK_HIGHRES.

Index: posix.cc
===================================================================
--- posix.cc	(revision 112466)
+++ posix.cc	(working copy)
@@ -71,7 +71,15 @@
 {
 #ifdef HAVE_CLOCK_GETTIME
   struct timespec now;
-  if (clock_gettime (CLOCK_REALTIME, &now) == 0)
+  int id;
+#ifdef CLOCK_MONOTONIC
+  id = CLOCK_MONOTONIC;
+#elif defined (CLOCK_HIGHRES)
+  id = CLOCK_HIGHRES;
+#else
+  id = CLOCK_REALTIME;
+#endif
+  if (clock_gettime (id, &now) == 0)
     {
       jlong result = (jlong) now.tv_sec;
       result = result * 1000 * 1000 + now.tv_nsec;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]