From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: get-internal-real-time using times() Date: Wed, 03 Sep 2003 08:37:18 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87d6ein7fl.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1062621282 5015 80.91.224.253 (3 Sep 2003 20:34:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 3 Sep 2003 20:34:42 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Sep 03 22:34:25 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19ueKe-00073K-00 for ; Wed, 03 Sep 2003 22:34:24 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19ueFa-00030I-NC for guile-devel@m.gmane.org; Wed, 03 Sep 2003 16:29:10 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 19uKSv-0001Rf-L6 for guile-devel@gnu.org; Tue, 02 Sep 2003 19:21:37 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 19uKEG-0006Rg-Mj for guile-devel@gnu.org; Tue, 02 Sep 2003 19:06:30 -0400 Original-Received: from [61.8.0.36] (helo=snoopy.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.22) id 19uJwK-0002K0-L7 for guile-devel@gnu.org; Tue, 02 Sep 2003 18:47:56 -0400 Original-Received: from mongrel.pacific.net.au (mongrel.pacific.net.au [61.8.0.107]) by snoopy.pacific.net.au (8.12.3/8.12.3/Debian-6.4) with ESMTP id h82MlrBt013218 for ; Wed, 3 Sep 2003 08:47:53 +1000 Original-Received: from localhost (ppp97.dyn228.pacific.net.au [203.143.228.97]) by mongrel.pacific.net.au (8.12.3/8.12.3/Debian-6.4) with ESMTP id h82MkdBC020388 for ; Wed, 3 Sep 2003 08:46:41 +1000 Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19uJm4-0000b2-00; Wed, 03 Sep 2003 08:37:20 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2738 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2738 --=-=-= * 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. --=-=-= Content-Disposition: attachment; filename=stime.c.real-time.diff --- 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); --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--