Skip to content

Commit

Permalink
Timestamps: Default to nanosecond-precision timestamps if clock_getti…
Browse files Browse the repository at this point in the history
…me()

is available.  Inspired by POSIX 2008 deprecating gettimeofday().
  • Loading branch information
kohler committed Sep 21, 2010
1 parent 731e87f commit e24deaa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
27 changes: 17 additions & 10 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -7412,16 +7412,6 @@ done



# Check whether --enable-nanotimestamp was given.
if test "${enable_nanotimestamp+set}" = set; then :
enableval=$enable_nanotimestamp;
fi

if test "x$enable_nanotimestamp" = xyes; then
$as_echo "#define HAVE_NANOTIMESTAMP_ENABLED 1" >>confdefs.h

fi

for ac_header in time.h
do :
ac_fn_cxx_check_header_mongrel "$LINENO" "time.h" "ac_cv_header_time_h" "$ac_includes_default"
Expand Down Expand Up @@ -7517,6 +7507,7 @@ _ACEOF

fi

have_clock_gettime=no
ac_fn_cxx_check_decl "$LINENO" "clock_gettime" "ac_cv_have_decl_clock_gettime" "#ifdef HAVE_TIME_H
# include <time.h>
#endif
Expand Down Expand Up @@ -7588,13 +7579,29 @@ if test "$ac_res" != no; then :

$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h

have_clock_gettime=yes
fi

POSIX_CLOCK_LIBS="$LIBS"

LIBS="$SAVELIBS"


# Check whether --enable-nanotimestamp was given.
if test "${enable_nanotimestamp+set}" = set; then :
enableval=$enable_nanotimestamp;
fi

# Default to nanosecond-precision timestamps if clock_gettime is available.
if test "x$enable_nanotimestamp" = x -a "x$have_clock_gettime" = xyes; then
enable_nanotimestamp=yes
fi
if test "x$enable_nanotimestamp" = xyes; then

$as_echo "#define HAVE_NANOTIMESTAMP_ENABLED 1" >>confdefs.h

fi



# Check whether --enable-tools was given.
Expand Down
14 changes: 9 additions & 5 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,6 @@ dnl
dnl timestamps
dnl

AC_ARG_ENABLE(nanotimestamp, [ --enable-nanotimestamp enable nanosecond timestamps])
if test "x$enable_nanotimestamp" = xyes; then
AC_DEFINE(HAVE_NANOTIMESTAMP_ENABLED)
fi

AC_CHECK_HEADERS(time.h)
AC_CHECK_SIZEOF([struct timeval])
AC_CHECK_TYPES([struct timespec], have_timespec=yes, have_timespec=no)
Expand All @@ -450,6 +445,15 @@ if test "x$have_timespec" = xyes; then
fi
CLICK_CHECK_POSIX_CLOCKS

AC_ARG_ENABLE(nanotimestamp, [ --enable-nanotimestamp enable nanosecond timestamps])
# Default to nanosecond-precision timestamps if clock_gettime is available.
if test "x$enable_nanotimestamp" = x -a "x$have_clock_gettime" = xyes; then
enable_nanotimestamp=yes
fi
if test "x$enable_nanotimestamp" = xyes; then
AC_DEFINE([HAVE_NANOTIMESTAMP_ENABLED], [1], [Define if nanosecond-granularity timestamps are enabled.])
fi


dnl
dnl check whether tools should be built for host or build
Expand Down
4 changes: 3 additions & 1 deletion m4/click.m4
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,14 @@ dnl POSIX_CLOCK_LIBS.
dnl
AC_DEFUN([CLICK_CHECK_POSIX_CLOCKS], [
have_clock_gettime=no
AC_CHECK_DECLS([clock_gettime], [], [], [#ifdef HAVE_TIME_H
# include <time.h>
#endif])
SAVELIBS="$LIBS"
AC_SEARCH_LIBS([clock_gettime], [rt],
[AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define if you have the clock_gettime function.])])
[AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define if you have the clock_gettime function.])
have_clock_gettime=yes])
POSIX_CLOCK_LIBS="$LIBS"
AC_SUBST(POSIX_CLOCK_LIBS)
LIBS="$SAVELIBS"
Expand Down

0 comments on commit e24deaa

Please sign in to comment.