Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen Since CLK_TCK is now a macro expanding into a f...



details:   https://anonhg.NetBSD.org/src/rev/58ecc2e4c02e
branches:  trunk
changeset: 533174:58ecc2e4c02e
user:      perry <perry%NetBSD.org@localhost>
date:      Sun Jun 23 20:21:08 2002 +0000

description:
Since CLK_TCK is now a macro expanding into a function call, cache its
output instead of using it willy nilly.

diffstat:

 lib/libc/gen/times.c |  16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diffs (45 lines):

diff -r 57dfc049a042 -r 58ecc2e4c02e lib/libc/gen/times.c
--- a/lib/libc/gen/times.c      Sun Jun 23 19:41:04 2002 +0000
+++ b/lib/libc/gen/times.c      Sun Jun 23 20:21:08 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: times.c,v 1.11 2000/01/22 22:19:13 mycroft Exp $       */
+/*     $NetBSD: times.c,v 1.12 2002/06/23 20:21:08 perry Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)times.c    8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: times.c,v 1.11 2000/01/22 22:19:13 mycroft Exp $");
+__RCSID("$NetBSD: times.c,v 1.12 2002/06/23 20:21:08 perry Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -60,7 +60,7 @@
  * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000,
  * but this would overflow if we switch to nanosec.
  */
-#define        CONVTCK(r)      (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
+#define        CONVTCK(r)      (r.tv_sec * clk_tck + r.tv_usec / (1000000 / clk_tck))
 
 clock_t
 times(tp)
@@ -68,8 +68,16 @@
 {
        struct rusage ru;
        struct timeval t;
+       static long clk_tck;
+       
+       _DIAGASSERT(tp != NULL);
 
-       _DIAGASSERT(tp != NULL);
+       /*
+        * we use a local copy of CLK_TCK because it expands to a
+        * moderately expensive function call.
+        */
+       if (clk_tck == 0)
+               clk_tck = CLK_TCK;
 
        if (getrusage(RUSAGE_SELF, &ru) < 0)
                return ((clock_t)-1);



Home | Main Index | Thread Index | Old Index