unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: get-internal-real-time using times()
Date: Wed, 03 Sep 2003 08:37:18 +1000	[thread overview]
Message-ID: <87d6ein7fl.fsf@zip.com.au> (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

             reply	other threads:[~2003-09-02 22:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-02 22:37 Kevin Ryde [this message]
2003-09-12 19:25 ` get-internal-real-time using times() Rob Browning
2003-09-12 23:46   ` Kevin Ryde
2003-09-13  2:51     ` Rob Browning
2003-09-15 22:47       ` Kevin Ryde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d6ein7fl.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).