* 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
* Re: get-internal-real-time using times()
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
0 siblings, 1 reply; 5+ messages in thread
From: Rob Browning @ 2003-09-12 19:25 UTC (permalink / raw)
Kevin Ryde <user42@zip.com.au> writes:
> * 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.
Presuming I understand what you're doing here (from a brief look), we
might want to be careful. If the old semantics of
get-internal-real-time relied on ftime, then people may have written
code that depends on the fact that get-internal-real-time has been
returning wall-clock time, and in fact, when contrasted to
get-internal-run-time's description (and given familiarity with the
"times" distinctions), that might be a reasonable presumption. Or did
I misunderstand?
--
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4
_______________________________________________
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
* Re: get-internal-real-time using times()
2003-09-12 19:25 ` Rob Browning
@ 2003-09-12 23:46 ` Kevin Ryde
2003-09-13 2:51 ` Rob Browning
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Ryde @ 2003-09-12 23:46 UTC (permalink / raw)
Rob Browning <rlb@defaultvalue.org> writes:
>
> If the old semantics of
> get-internal-real-time relied on ftime, then people may have written
> code that depends on the fact that get-internal-real-time has been
> returning wall-clock time,
I guess that's possible, though I might think it unlikely anyone who
understands the distinction would assume a function called `real-time'
in fact gives wall time.
> and in fact, when contrasted to
> get-internal-run-time's description (and given familiarity with the
> "times" distinctions), that might be a reasonable presumption.
Or one could assume that since -run-time is unaffected then -real-time
is also unaffected.
If the system time doesn't change too often then I guess there's not
much difference. But I can't help thinking that it's not good for a
function called real-time to go backwards or suddenly jump forwards.
_______________________________________________
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
* Re: get-internal-real-time using times()
2003-09-12 23:46 ` Kevin Ryde
@ 2003-09-13 2:51 ` Rob Browning
2003-09-15 22:47 ` Kevin Ryde
0 siblings, 1 reply; 5+ messages in thread
From: Rob Browning @ 2003-09-13 2:51 UTC (permalink / raw)
Kevin Ryde <user42@zip.com.au> writes:
> I guess that's possible, though I might think it unlikely anyone who
> understands the distinction would assume a function called `real-time'
> in fact gives wall time.
Hmm. I don't know. Maybe I'm daft, but I could see myself at least
wondering, -- i.e. "perhaps real-time == time in the real-world",
though as you mention...
> If the system time doesn't change too often then I guess there's not
> much difference. But I can't help thinking that it's not good for a
> function called real-time to go backwards or suddenly jump forwards.
Hmm. You mean because of timezones/leap-foo, etc.? If so, good
point. I'd say we need better docs, better functions, or both, and
either way, a good NEWS entry.
--
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4
_______________________________________________
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
* Re: get-internal-real-time using times()
2003-09-13 2:51 ` Rob Browning
@ 2003-09-15 22:47 ` Kevin Ryde
0 siblings, 0 replies; 5+ messages in thread
From: Kevin Ryde @ 2003-09-15 22:47 UTC (permalink / raw)
Rob Browning <rlb@defaultvalue.org> writes:
>
> Hmm. You mean because of timezones
Timezones and daylight saving won't affect ftime on a unix system, but
might on DOS where the system time is local time.
> /leap-foo,
Not sure what normally happens for leap seconds. If the system time
is properly tied to UTC like srfi-19.scm assumes then I think for a
leap second 23:59:59 to 00:00:00 will take 2 seconds of real time. I
imagine only serious users would attempt to enforce that though.
> etc.?
Sudden changes with stime would be the main concern, gradual changes
with adjtime would be less of a worry but still not ideal.
> If so, good
> point. I'd say we need better docs, better functions, or both, and
> either way, a good NEWS entry.
Oh well, these sort of things always depend on the intended usage,
which is why I ask about the current theory. I'd certainly like to
tighten up the docs though.
_______________________________________________
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).