UnixOperatingSystem.st
changeset 8592 1c5216cd013e
parent 8564 48fd5e5b9d21
child 8599 9edfb6a871bf
--- a/UnixOperatingSystem.st	Thu Sep 23 20:24:37 2004 +0200
+++ b/UnixOperatingSystem.st	Thu Sep 23 21:26:39 2004 +0200
@@ -10,6 +10,8 @@
  hereby transferred.
 "
 
+'From Smalltalk/X, Version:5.2.4 on 22-09-2004 at 20:27:22'                     !
+
 "{ Package: 'stx:libbasic' }"
 
 AbstractOperatingSystem subclass:#UnixOperatingSystem
@@ -8093,31 +8095,35 @@
      on those, the returned value may be rounded towards some internal
      clock resolution value."
 
-    |seconds millis micros error|
+    |seconds micros error|
 
 %{
-#if defined(HAS_GETTIMEOFDAY)
-    long __seconds = 0;
-    long __millis = 0;
-    long __micros = 0;
-
+#if defined(_POSIX_MONOTONIC_CLOCK)
+    unsigned long __seconds = 0;
+    unsigned long __micros = 0;
+    struct timespec ts;
+
+    if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
+        error = @symbol(bad);
+
+    seconds = __MKUINT(ts.tv_sec);
+    micros  = __MKUINT(ts.tv_nsec / 1000);
+
+#elif defined(HAS_GETTIMEOFDAY)
     struct timeval tb;
 
     gettimeofday(&tb, NULL /* &tzb */);
-    __seconds = tb.tv_sec;
-    __micros = tb.tv_usec;
-    if (__micros >= (1000*1000)) {
+    if (tb.tv_usec >= (1000*1000)) {
         error = @symbol(bad);
     }
 
-    seconds = __MKINT(__seconds);
-    millis  = __MKINT(__millis);
-    micros  = __MKINT(__micros);
+    seconds = __MKUINT(tb.tv_sec);
+    micros  = __MKUINT(tb.tv_usec);
 #endif
 %}.
 
     seconds notNil ifTrue:[
-        ^ (((seconds * 1000) + millis) * 1000) + micros
+        ^ (seconds * 1000000) + micros
     ].
     error isNil ifTrue:[
         ^ self getMillisecondTime * 1000
@@ -8150,11 +8156,20 @@
 
     long t = 0;
 
+
+#if defined(_POSIX_MONOTONIC_CLOCK)
+    struct timespec ts;
+
+    if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
+        goto err;
+
+    t = ts.tv_sec*1000 + ts.tv_nsec/1000000;
+
+#elif defined(_SC_CLK_TCK)
 /*
- * We prefer times here, since it is immune to clock changes!
+ * We prefer times here, since it is monotonic and immune to clock changes
+ *  but: it has less precision!
  */
-
-#if defined(_SC_CLK_TCK)
 # include <sys/times.h>
 
     static int millisecondsPerTick;
@@ -8168,6 +8183,9 @@
         if (ticksPerSecond > 1000)
             goto err;
         millisecondsPerTick = 1000 / ticksPerSecond;
+/*
+printf("milliSecondsPerTick: %d\n", millisecondsPerTick);
+*/
     }
 
     ticks = times(&tb);
@@ -12231,7 +12249,7 @@
 !UnixOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.215 2004-09-21 17:52:44 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.216 2004-09-23 19:26:39 stefan Exp $'
 ! !
 
 UnixOperatingSystem initialize!