unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* get-internal-real-time using times()
@ 2003-09-02 22:37 Kevin Ryde
  2003-09-12 19:25 ` Rob Browning
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Ryde @ 2003-09-02 22:37 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 398 bytes --]

        * stime.c (scm_get_internal_real_time, scm_your_base, scm_init_stime):
        Use times() when available, for a genuine real-time (unaffected by
        stime system time changes).

The name "real-time" suggests to me something independent of the
system date/time.  And since the return is clock ticks, times() would
seem natural.  Unless there's a particular reason it isn't already so.


[-- Attachment #2: stime.c.real-time.diff --]
[-- Type: text/plain, Size: 1148 bytes --]

--- stime.c.~1.79.~	1970-01-01 10:00:00.000000000 +1000
+++ stime.c	2003-08-31 15:19:06.000000000 +1000
@@ -87,7 +87,13 @@
 # endif
 #endif
 
-#ifdef HAVE_FTIME
+
+/* times() returns a genuine real-time, meaning it's unaffected by system
+   time changes made by stime().  If times() isn't available (mingw for
+   instance) then we have to fall back on ftime() or time().  */
+#if HAVE_TIMES
+clock_t scm_your_base;
+#elif HAVE_FTIME
 struct timeb scm_your_base = {0};
 #else
 timet scm_your_base = 0;
@@ -99,7 +105,10 @@
 	    "started.")
 #define FUNC_NAME s_scm_get_internal_real_time
 {
-#ifdef HAVE_FTIME
+#if HAVE_TIMES
+  struct tms dummy;
+  return scm_long2num (times (&dummy) - scm_your_base);
+#elif HAVE_FTIME
   struct timeb time_buffer;
 
   SCM tmp;
@@ -664,7 +673,13 @@
   scm_c_define ("internal-time-units-per-second",
 		scm_long2num((long) SCM_TIME_UNITS_PER_SECOND));
 
-#ifdef HAVE_FTIME
+#if HAVE_TIMES
+  if (!scm_your_base)
+    {
+      struct tms dummy;
+      scm_your_base = times(&dummy);
+    }
+#elif HAVE_FTIME
   if (!scm_your_base.time) ftime(&scm_your_base);
 #else
   if (!scm_your_base) time(&scm_your_base);

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-09-15 22:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-02 22:37 get-internal-real-time using times() Kevin Ryde
2003-09-12 19:25 ` Rob Browning
2003-09-12 23:46   ` Kevin Ryde
2003-09-13  2:51     ` Rob Browning
2003-09-15 22:47       ` Kevin Ryde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).