aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2008-05-12 02:04:21 +0000
committerYang Tse <yangsita@gmail.com>2008-05-12 02:04:21 +0000
commited80eb5b0f11d70db37e8a3b0406fa906842a962 (patch)
tree1be50fd602da20c0ba422ba1ef86a45a7cdc4f39
parent60dd765b3dd73bd957bff42a990ba391c843a9ff (diff)
configure script will now define HAVE_CLOCK_GETTIME_MONOTONIC symbol only
when function clock_gettime() is available and the monotonic timer is also available. Otherwise, in some cases, librt or libposix4 could be used for linking even when finally not using the clock_gettime() function due to lack of the monotonic clock.
-rw-r--r--acinclude.m4144
-rw-r--r--ares/acinclude.m4144
-rw-r--r--ares/ares__timeval.c2
-rw-r--r--ares/configure.ac5
-rw-r--r--configure.ac5
-rw-r--r--lib/timeval.c2
-rw-r--r--src/curlutil.c2
-rw-r--r--tests/libtest/testutil.c2
8 files changed, 196 insertions, 110 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 66d74869b..9c5ff054c 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1814,29 +1814,16 @@ AC_DEFUN([TYPE_IN_ADDR_T],
]) dnl AC_CHECK_TYPE
]) dnl AC_DEFUN
-dnl CURL_CHECK_LIBS_CLOCK_GETTIME
+dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
dnl -------------------------------------------------
-dnl Check for libraries needed for clock_gettime,
-dnl and prepended to LIBS any needed libraries.
+dnl Check if monotonic clock_gettime is available.
-AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
+AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
AC_REQUIRE([AC_HEADER_TIME])dnl
AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
- #
- AC_MSG_CHECKING([for clock_gettime in libraries])
- #
- curl_cv_save_LIBS="$LIBS"
- curl_cv_gclk_LIBS="unknown"
- #
- for x_xlibs in '' '-lrt' '-lposix4' ; do
- if test -z "$x_xlibs"; then
- LIBS="$curl_cv_save_LIBS"
- else
- LIBS="$x_xlibs $curl_cv_save_LIBS"
- fi
- AC_LINK_IFELSE([
- AC_LANG_PROGRAM([
-#undef inline
+ AC_MSG_CHECKING([for monotonic clock_gettime])
+ AC_COMPILE_IFELSE([
+ AC_LANG_PROGRAM([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -1850,43 +1837,98 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
#include <time.h>
#endif
#endif
- ],[
- (void)clock_gettime(0, 0);
- ])
],[
- curl_cv_gclk_LIBS="$x_xlibs"
- break
+ struct timespec ts;
+ (void)clock_gettime(CLOCK_MONOTONIC, &ts);
])
- done
- #
- LIBS="$curl_cv_save_LIBS"
+ ],[
+ AC_MSG_RESULT([yes])
+ ac_cv_func_clock_gettime="yes"
+ ],[
+ AC_MSG_RESULT([no])
+ ac_cv_func_clock_gettime="no"
+ ])
+ dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally
+ dnl postponed until library linking checks for clock_gettime pass.
+]) dnl AC_DEFUN
+
+dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
+dnl -------------------------------------------------
+dnl If monotonic clock_gettime is available then,
+dnl check and prepended to LIBS any needed libraries.
+
+AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
+ AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
#
- case X-"$curl_cv_gclk_LIBS" in
- X-unknown)
- AC_MSG_RESULT([cannot find clock_gettime])
- ac_cv_func_clock_gettime="no"
- ;;
- X-)
- AC_MSG_RESULT([no additional lib required])
- ac_cv_func_clock_gettime="yes"
- ;;
- *)
- if test -z "$curl_cv_save_LIBS"; then
- LIBS="$curl_cv_gclk_LIBS"
+ if test "$ac_cv_func_clock_gettime" = "yes"; then
+ #
+ AC_MSG_CHECKING([for clock_gettime in libraries])
+ #
+ curl_cv_save_LIBS="$LIBS"
+ curl_cv_gclk_LIBS="unknown"
+ #
+ for x_xlibs in '' '-lrt' '-lposix4' ; do
+ if test -z "$x_xlibs"; then
+ LIBS="$curl_cv_save_LIBS"
else
- LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
+ LIBS="$x_xlibs $curl_cv_save_LIBS"
fi
- AC_MSG_RESULT([$curl_cv_gclk_LIBS])
- ac_cv_func_clock_gettime="yes"
- ;;
- esac
- #
- case "$ac_cv_func_clock_gettime" in
- yes)
- AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME, 1,
- [Define to 1 if you have the clock_gettime function.])
- ;;
- esac
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#ifdef TIME_WITH_SYS_TIME
+#include <time.h>
+#endif
+#else
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+#endif
+ ],[
+ struct timespec ts;
+ (void)clock_gettime(CLOCK_MONOTONIC, &ts);
+ ])
+ ],[
+ curl_cv_gclk_LIBS="$x_xlibs"
+ break
+ ])
+ done
+ #
+ LIBS="$curl_cv_save_LIBS"
+ #
+ case X-"$curl_cv_gclk_LIBS" in
+ X-unknown)
+ AC_MSG_RESULT([cannot find clock_gettime])
+ AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
+ ac_cv_func_clock_gettime="no"
+ ;;
+ X-)
+ AC_MSG_RESULT([no additional lib required])
+ ac_cv_func_clock_gettime="yes"
+ ;;
+ *)
+ if test -z "$curl_cv_save_LIBS"; then
+ LIBS="$curl_cv_gclk_LIBS"
+ else
+ LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
+ fi
+ AC_MSG_RESULT([$curl_cv_gclk_LIBS])
+ ac_cv_func_clock_gettime="yes"
+ ;;
+ esac
+ #
+ case "$ac_cv_func_clock_gettime" in
+ yes)
+ AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
+ [Define to 1 if you have the clock_gettime function and monotonic timer.])
+ ;;
+ esac
+ #
+ fi
#
]) dnl AC_DEFUN
diff --git a/ares/acinclude.m4 b/ares/acinclude.m4
index 2a7bc02f6..fb00d0981 100644
--- a/ares/acinclude.m4
+++ b/ares/acinclude.m4
@@ -1283,29 +1283,16 @@ AC_DEFUN([TYPE_IN_ADDR_T],
]) dnl AC_CHECK_TYPE
]) dnl AC_DEFUN
-dnl CURL_CHECK_LIBS_CLOCK_GETTIME
+dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
dnl -------------------------------------------------
-dnl Check for libraries needed for clock_gettime,
-dnl and prepended to LIBS any needed libraries.
+dnl Check if monotonic clock_gettime is available.
-AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
+AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
AC_REQUIRE([AC_HEADER_TIME])dnl
AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
- #
- AC_MSG_CHECKING([for clock_gettime in libraries])
- #
- curl_cv_save_LIBS="$LIBS"
- curl_cv_gclk_LIBS="unknown"
- #
- for x_xlibs in '' '-lrt' '-lposix4' ; do
- if test -z "$x_xlibs"; then
- LIBS="$curl_cv_save_LIBS"
- else
- LIBS="$x_xlibs $curl_cv_save_LIBS"
- fi
- AC_LINK_IFELSE([
- AC_LANG_PROGRAM([
-#undef inline
+ AC_MSG_CHECKING([for monotonic clock_gettime])
+ AC_COMPILE_IFELSE([
+ AC_LANG_PROGRAM([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -1319,43 +1306,98 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
#include <time.h>
#endif
#endif
- ],[
- (void)clock_gettime(0, 0);
- ])
],[
- curl_cv_gclk_LIBS="$x_xlibs"
- break
+ struct timespec ts;
+ (void)clock_gettime(CLOCK_MONOTONIC, &ts);
])
- done
- #
- LIBS="$curl_cv_save_LIBS"
+ ],[
+ AC_MSG_RESULT([yes])
+ ac_cv_func_clock_gettime="yes"
+ ],[
+ AC_MSG_RESULT([no])
+ ac_cv_func_clock_gettime="no"
+ ])
+ dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally
+ dnl postponed until library linking checks for clock_gettime pass.
+]) dnl AC_DEFUN
+
+dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
+dnl -------------------------------------------------
+dnl If monotonic clock_gettime is available then,
+dnl check and prepended to LIBS any needed libraries.
+
+AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
+ AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
#
- case X-"$curl_cv_gclk_LIBS" in
- X-unknown)
- AC_MSG_RESULT([cannot find clock_gettime])
- ac_cv_func_clock_gettime="no"
- ;;
- X-)
- AC_MSG_RESULT([no additional lib required])
- ac_cv_func_clock_gettime="yes"
- ;;
- *)
- if test -z "$curl_cv_save_LIBS"; then
- LIBS="$curl_cv_gclk_LIBS"
+ if test "$ac_cv_func_clock_gettime" = "yes"; then
+ #
+ AC_MSG_CHECKING([for clock_gettime in libraries])
+ #
+ curl_cv_save_LIBS="$LIBS"
+ curl_cv_gclk_LIBS="unknown"
+ #
+ for x_xlibs in '' '-lrt' '-lposix4' ; do
+ if test -z "$x_xlibs"; then
+ LIBS="$curl_cv_save_LIBS"
else
- LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
+ LIBS="$x_xlibs $curl_cv_save_LIBS"
fi
- AC_MSG_RESULT([$curl_cv_gclk_LIBS])
- ac_cv_func_clock_gettime="yes"
- ;;
- esac
- #
- case "$ac_cv_func_clock_gettime" in
- yes)
- AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME, 1,
- [Define to 1 if you have the clock_gettime function.])
- ;;
- esac
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#ifdef TIME_WITH_SYS_TIME
+#include <time.h>
+#endif
+#else
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+#endif
+ ],[
+ struct timespec ts;
+ (void)clock_gettime(CLOCK_MONOTONIC, &ts);
+ ])
+ ],[
+ curl_cv_gclk_LIBS="$x_xlibs"
+ break
+ ])
+ done
+ #
+ LIBS="$curl_cv_save_LIBS"
+ #
+ case X-"$curl_cv_gclk_LIBS" in
+ X-unknown)
+ AC_MSG_RESULT([cannot find clock_gettime])
+ AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
+ ac_cv_func_clock_gettime="no"
+ ;;
+ X-)
+ AC_MSG_RESULT([no additional lib required])
+ ac_cv_func_clock_gettime="yes"
+ ;;
+ *)
+ if test -z "$curl_cv_save_LIBS"; then
+ LIBS="$curl_cv_gclk_LIBS"
+ else
+ LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
+ fi
+ AC_MSG_RESULT([$curl_cv_gclk_LIBS])
+ ac_cv_func_clock_gettime="yes"
+ ;;
+ esac
+ #
+ case "$ac_cv_func_clock_gettime" in
+ yes)
+ AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
+ [Define to 1 if you have the clock_gettime function and monotonic timer.])
+ ;;
+ esac
+ #
+ fi
#
]) dnl AC_DEFUN
diff --git a/ares/ares__timeval.c b/ares/ares__timeval.c
index 2fbf1688c..6de6c6552 100644
--- a/ares/ares__timeval.c
+++ b/ares/ares__timeval.c
@@ -33,7 +33,7 @@ struct timeval ares__tvnow(void)
return now;
}
-#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
struct timeval ares__tvnow(void)
{
diff --git a/ares/configure.ac b/ares/configure.ac
index 28f90c8ab..70dbcce18 100644
--- a/ares/configure.ac
+++ b/ares/configure.ac
@@ -261,9 +261,10 @@ dnl socket lib?
AC_CHECK_FUNC(connect, , [ AC_CHECK_LIB(socket, connect) ])
dnl **********************************************************************
-dnl Check for libraries needed for function clock_gettime
+dnl In case that function clock_gettime with monotonic timer is available,
+dnl check for additional required libraries.
dnl **********************************************************************
-CURL_CHECK_LIBS_CLOCK_GETTIME
+CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
AC_MSG_CHECKING([whether to use libgcc])
AC_ARG_ENABLE(libgcc,
diff --git a/configure.ac b/configure.ac
index 0ef6a3942..3e54496c2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -568,9 +568,10 @@ dnl socket lib?
AC_CHECK_FUNC(connect, , [ AC_CHECK_LIB(socket, connect) ])
dnl **********************************************************************
-dnl Check for libraries needed for function clock_gettime
+dnl In case that function clock_gettime with monotonic timer is available,
+dnl check for additional required libraries.
dnl **********************************************************************
-CURL_CHECK_LIBS_CLOCK_GETTIME
+CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
dnl **********************************************************************
dnl The preceding library checks are all potentially useful for test
diff --git a/lib/timeval.c b/lib/timeval.c
index 0bedfbe81..74f0b3a2f 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -39,7 +39,7 @@ struct timeval curlx_tvnow(void)
return now;
}
-#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
struct timeval curlx_tvnow(void)
{
diff --git a/src/curlutil.c b/src/curlutil.c
index a687a9a44..56cfa53c1 100644
--- a/src/curlutil.c
+++ b/src/curlutil.c
@@ -41,7 +41,7 @@ struct timeval cutil_tvnow(void)
return now;
}
-#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
struct timeval cutil_tvnow(void)
{
diff --git a/tests/libtest/testutil.c b/tests/libtest/testutil.c
index df90cdccb..435b30e09 100644
--- a/tests/libtest/testutil.c
+++ b/tests/libtest/testutil.c
@@ -41,7 +41,7 @@ struct timeval tutil_tvnow(void)
return now;
}
-#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
struct timeval tutil_tvnow(void)
{