# HG changeset patch # User Akim Demaille # Date 1538453959 -7200 # Node ID d8ad6b800760de4963f4e8494cd21563da2a670f # Parent cd549182ef0ed27ceb39398ba6d55ca6ba776b14 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 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. diff -r cd549182ef0e -r d8ad6b800760 ChangeLog --- 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 + + 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 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 sh-filename: New module. diff -r cd549182ef0e -r d8ad6b800760 lib/timevar.c --- 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 +#include #include -#include +#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) #include "xalloc.h" -#if HAVE_SYS_TIME_H -# include -#endif - -#ifdef HAVE_SYS_TIMES_H -# include -#endif #ifdef HAVE_SYS_RESOURCE_H # include #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 } diff -r cd549182ef0e -r d8ad6b800760 lib/timevar.h --- 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 . */ #ifndef _TIMEVAR_H -#define _TIMEVAR_H +# define _TIMEVAR_H 1 + +# include + +# 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 */ diff -r cd549182ef0e -r d8ad6b800760 m4/timevar.m4 --- 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 . -# 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 @@ -44,17 +44,4 @@ # include #endif ]) - -AC_CHECK_TYPES([clock_t, struct tms], [], [], -[$ac_includes_default -#if HAVE_SYS_TIME_H -# include -#endif -#if HAVE_SYS_TIMES_H -# include -#endif -#if HAVE_SYS_RESOURCE_H -# include -#endif ]) -]) diff -r cd549182ef0e -r d8ad6b800760 modules/timevar --- 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