This is the mail archive of the 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

Cédric Berger wrote:
Hi Tom,

+_Jv_platform_nanotime ()
+  struct timespec now;
+  if (clock_gettime (CLOCK_REALTIME, &now) == 0)
+    {
+      jlong result = (jlong) now.tv_sec;
+      result = result * 1000 * 1000 + now.tv_nsec;
+      return result;
+    }
+  // clock_gettime failed, but we can fall through.
+  return _Jv_platform_gettimeofday () * 1000LL;

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

The problem is when you use CLOCK_REALTIME to measure
elapsed time and the user changes the time...
I had to write the same code for another project, and
I used the following snipped for Linux/BSD/Solaris:

  int        id;
  #error bad platform
    if (clock_gettime(id, &tv) - 0)

I think this is an excellent idea.

I cannot begin to tell you how much a pain in the a** it is to manage multiple time outs on a single thread while at the same time trying to maintain a 'wall clock' the can be changed.

David Daney

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