changeset 39884:d8ad6b800760

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.
author Akim Demaille <akim.demaille@gmail.com>
date Tue, 02 Oct 2018 06:19:19 +0200
parents cd549182ef0e
children 7ca385183654
files ChangeLog lib/timevar.c lib/timevar.h m4/timevar.m4 modules/timevar
diffstat 5 files changed, 32 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Oct 05 01:38:46 2018 +0200
+++ b/ChangeLog	Tue Oct 02 06:19:19 2018 +0200
@@ -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.
--- a/lib/timevar.c	Fri Oct 05 01:38:46 2018 +0200
+++ b/lib/timevar.c	Tue Oct 02 06:19:19 2018 +0200
@@ -24,38 +24,19 @@
 #include "timevar.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#include <stdlib.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 @@
 # 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 @@
 #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 @@
     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 @@
 
 #if defined USE_TIMES
   ticks_to_msec = TICKS_TO_MSEC;
-#elif defined USE_CLOCK
-  clocks_to_msec = CLOCKS_TO_MSEC;
 #endif
 }
 
--- a/lib/timevar.h	Fri Oct 05 01:38:46 2018 +0200
+++ b/lib/timevar.h	Tue Oct 02 06:19:19 2018 +0200
@@ -19,7 +19,13 @@
    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 @@
 /* Set to to nonzero to enable timing variables.  */
 extern int timevar_enabled;
 
+# ifdef  __cplusplus
+}
+# endif
+
 #endif /* ! _TIMEVAR_H */
--- a/m4/timevar.m4	Fri Oct 05 01:38:46 2018 +0200
+++ b/m4/timevar.m4	Tue Oct 02 06:19:19 2018 +0200
@@ -17,11 +17,11 @@
 # 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 @@
 # 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
 ])
-])
--- a/modules/timevar	Fri Oct 05 01:38:46 2018 +0200
+++ b/modules/timevar	Tue Oct 02 06:19:19 2018 +0200
@@ -8,8 +8,11 @@
 
 Depends-on:
 gettext-h
+stdlib
+sys_time
+sys_times
+times
 xalloc
-stdlib
 
 configure.ac:
 gl_TIMEVAR