From 2c8e5297e7481a931afb7a64fd8528bc7f7db86d Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 27 Apr 2012 12:51:32 +0200 Subject: [PATCH] Use clock() when times() is not available. * configure.ac: Check for times() and sys/times.h. * src/misc/timer.hh: Include sys/times.h conditionally and use clock() if times() is not available. Reported by Yann Thierry-Mieg. --- configure.ac | 3 ++- src/misc/timer.hh | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 0d6146d2b..92d9712f8 100644 --- a/configure.ac +++ b/configure.ac @@ -67,7 +67,8 @@ AX_CHECK_LBTT AX_CHECK_GSPNLIB AX_CHECK_BOOST([1.34], [103400]) -AC_CHECK_FUNCS([srand48 drand48]) +AC_CHECK_HEADERS([sys/times.h]) +AC_CHECK_FUNCS([times srand48 drand48]) LT_CONFIG_LTDL_DIR([ltdl]) LT_INIT([win32-dll]) diff --git a/src/misc/timer.hh b/src/misc/timer.hh index abadd33f2..207b38b6c 100644 --- a/src/misc/timer.hh +++ b/src/misc/timer.hh @@ -1,7 +1,8 @@ -// Copyright (C) 2009, 2011 Laboratoire de Recherche et Developpement -// de l'Epita (LRDE). +// -*- coding: utf-8 -*- +// Copyright (C) 2009, 2011, 2012 Laboratoire de Recherche et +// Développement de l'Epita (LRDE). // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), -// département Systèmes Répartis Coopératifs (SRC), Université Pierre +// département Systèmes Répartis Coopératifs (SRC), Université Pierre // et Marie Curie. // // This file is part of Spot, a model checking library. @@ -24,11 +25,16 @@ #ifndef SPOT_MISC_TIMER_HH # define SPOT_MISC_TIMER_HH +# include "misc/_config.h" # include # include # include # include -# include +# if SPOT_HAVE_SYS_TIMES_H +# include +# endif +# include + namespace spot { @@ -39,7 +45,7 @@ namespace spot struct time_info { time_info() - : utime(), stime(0) + : utime(0), stime(0) { } clock_t utime; @@ -61,20 +67,28 @@ namespace spot { assert(!running); running = true; +#ifdef SPOT_HAVE_TIMES struct tms tmp; times(&tmp); start_.utime = tmp.tms_utime; start_.stime = tmp.tms_stime; +#else + start_.utime = clock(); +#endif } /// Stop a time interval and update the sum of all intervals. void stop() { +#ifdef SPOT_HAVE_TIMES struct tms tmp; times(&tmp); total_.utime += tmp.tms_utime - start_.utime; total_.stime += tmp.tms_stime - start_.stime; +#else + total_.utime += clock() - start_.utime; +#endif assert(running); running = false; }