* 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-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.
#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
# 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
#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. */
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
}
}
#if defined USE_TIMES
ticks_to_msec = TICKS_TO_MSEC;
-#elif defined USE_CLOCK
- clocks_to_msec = CLOCKS_TO_MSEC;
#endif
}
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
/* Set to to nonzero to enable timing variables. */
extern int timevar_enabled;
+# ifdef __cplusplus
+}
+# endif
+
#endif /* ! _TIMEVAR_H */
# 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>
# 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
-])
])
Depends-on:
gettext-h
-xalloc
stdlib
+sys_time
+sys_times
+times
+xalloc
configure.ac:
gl_TIMEVAR