]> Savannah Git Hosting - gnulib.git/commitdiff
timevar: rely on gnulib modules for time portability.
authorAkim Demaille <akim.demaille@gmail.com>
Tue, 2 Oct 2018 04:19:19 +0000 (06:19 +0200)
committerAkim Demaille <akim.demaille@gmail.com>
Fri, 5 Oct 2018 04:13:54 +0000 (06:13 +0200)
* modules/timevar (Depends-on): Add sys_time, sys_times, and times.
* m4/timevar.m4: Don't check for clock_t and struct tms,
guaranteed by gnulib.
* lib/timevar.h: Use extern "C" protection.
Include <stdio.h> for FILE.
* lib/timevar.c: Include sys/time.h, sys/times.h unconditionally,
they are guaranteed by gnulib.
Remove uses of clock as (now useless) fallback.

ChangeLog
lib/timevar.c
lib/timevar.h
m4/timevar.m4
modules/timevar

index d860386441277ad4a154165f165da485e4f80e1a..c14e0a2545ec1c837998816921464b0ea18a17bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2018-10-05  Akim Demaille  <akim@lrde.epita.fr>
+
+       timevar: rely on gnulib modules for time portability.
+       * modules/timevar (Depends-on): Add sys_time, sys_times, and times.
+       * m4/timevar.m4: Don't check for clock_t and struct tms,
+       guaranteed by gnulib.
+       * lib/timevar.h: Use extern "C" protection.
+       Include <stdio.h> for FILE.
+       * lib/timevar.c: Include sys/time.h, sys/times.h unconditionally,
+       they are guaranteed by gnulib.
+       Remove uses of clock as (now useless) fallback.
+
 2018-10-04  Bruno Haible  <bruno@clisp.org>
 
        sh-filename: New module.
index a2d2433923d65a94a5a125148001a671be788fe3..391802838b401532eb55432529043b0dad9d1b28 100644 (file)
 #include "timevar.h"
 
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/times.h>
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 #include "xalloc.h"
 
-#if HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-
-#ifdef HAVE_SYS_TIMES_H
-# include <sys/times.h>
-#endif
 #ifdef HAVE_SYS_RESOURCE_H
 # include <sys/resource.h>
 #endif
 
-#ifndef HAVE_CLOCK_T
-typedef int clock_t;
-#endif
-
-#ifndef HAVE_STRUCT_TMS
-struct tms
-{
-  clock_t tms_utime;
-  clock_t tms_stime;
-  clock_t tms_cutime;
-  clock_t tms_cstime;
-};
-#endif
-
 /* Calculation of scale factor to convert ticks to microseconds.
    We mustn't use CLOCKS_PER_SEC except with clock().  */
 #if HAVE_SYSCONF && defined _SC_CLK_TCK
@@ -79,17 +60,12 @@ struct tms
 # define USE_GETRUSAGE
 # define HAVE_USER_TIME
 # define HAVE_SYS_TIME
-#elif defined HAVE_CLOCK
-# define USE_CLOCK
-# define HAVE_USER_TIME
 #endif
 
 #if defined USE_TIMES && !defined HAVE_DECL_TIMES
 clock_t times (struct tms *);
 #elif defined USE_GETRUSAGE && !defined HAVE_DECL_GETRUSAGE
 int getrusage (int, struct rusage *);
-#elif defined USE_CLOCK && !defined HAVE_DECL_CLOCK
-clock_t clock (void);
 #endif
 
 /* libc is very likely to have snuck a call to sysconf() into one of
@@ -99,9 +75,6 @@ clock_t clock (void);
 #ifdef USE_TIMES
 static float ticks_to_msec;
 # define TICKS_TO_MSEC (1.0 / TICKS_PER_SECOND)
-#elif defined USE_CLOCK
-static float clocks_to_msec;
-# define CLOCKS_TO_MSEC (1.0 / CLOCKS_PER_SEC)
 #endif
 
 /* See timevar.h for an explanation of timing variables.  */
@@ -184,8 +157,6 @@ set_to_current_time (struct timevar_time_def *now)
     getrusage (RUSAGE_CHILDREN, &rusage);
     now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
     now->sys  = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
-#elif defined USE_CLOCK
-    now->user = clock () * clocks_to_msec;
 #endif
   }
 }
@@ -229,8 +200,6 @@ timevar_init ()
 
 #if defined USE_TIMES
   ticks_to_msec = TICKS_TO_MSEC;
-#elif defined USE_CLOCK
-  clocks_to_msec = CLOCKS_TO_MSEC;
 #endif
 }
 
index 88c4aa864ad7d342754ef90d0119fdc65b8d3d09..7c9258409b17f0955722ecd89b0048bc02a41395 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #ifndef _TIMEVAR_H
-#define _TIMEVAR_H
+# define _TIMEVAR_H 1
+
+# include <stdio.h>
+
+# ifdef  __cplusplus
+extern "C" {
+# endif
 
 /* Timing variables are used to measure elapsed time in various
    portions of the application.  Each measures elapsed user, system, and
@@ -121,4 +127,8 @@ void timevar_print (FILE *fp);
 /* Set to to nonzero to enable timing variables.  */
 extern int timevar_enabled;
 
+# ifdef  __cplusplus
+}
+# endif
+
 #endif /* ! _TIMEVAR_H */
index b418413420ca622b57c2138a90bc68a880cdc5b8..c790ed0a9a44a6c1b1c5c234d3324e1939f12371 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# serial 2
+# serial 3
 
 AC_DEFUN([gl_TIMEVAR],
 [AC_CHECK_HEADERS([sys/time.h sys/times.h])
- AC_CHECK_HEADERS([sys/resource.h],,,
+ AC_CHECK_HEADERS([sys/resource.h], [], [],
    [$ac_includes_default
 #if HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -44,17 +44,4 @@ AC_CHECK_DECLS([getrusage, times, clock, sysconf], [], [],
 # include <sys/resource.h>
 #endif
 ])
-
-AC_CHECK_TYPES([clock_t, struct tms], [], [],
-[$ac_includes_default
-#if HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-#if HAVE_SYS_TIMES_H
-# include <sys/times.h>
-#endif
-#if HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#endif
-])
 ])
index fdbbd6b79d99b9a116073828ecc9dc36f9abb385..05dac76094c31032d31ab93e2f92d788e9720940 100644 (file)
@@ -8,8 +8,11 @@ m4/timevar.m4
 
 Depends-on:
 gettext-h
-xalloc
 stdlib
+sys_time
+sys_times
+times
+xalloc
 
 configure.ac:
 gl_TIMEVAR