timeval: use CLOCK_MONOTONIC_RAW if available
Reported-by: Harry Sintonen Ref: #11288 Closes #11291
This commit is contained in:
parent
f06cc4f85e
commit
c92b7228c5
32
acinclude.m4
32
acinclude.m4
@ -1072,6 +1072,38 @@ AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
|
|||||||
dnl until library linking and run-time checks for clock_gettime succeed.
|
dnl until library linking and run-time checks for clock_gettime succeed.
|
||||||
])
|
])
|
||||||
|
|
||||||
|
dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC_RAW
|
||||||
|
dnl -------------------------------------------------
|
||||||
|
dnl Check if monotonic clock_gettime is available.
|
||||||
|
|
||||||
|
AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC_RAW], [
|
||||||
|
AC_CHECK_HEADERS(sys/types.h sys/time.h)
|
||||||
|
AC_MSG_CHECKING([for raw monotonic clock_gettime])
|
||||||
|
#
|
||||||
|
if test "x$dontwant_rt" = "xno" ; then
|
||||||
|
AC_COMPILE_IFELSE([
|
||||||
|
AC_LANG_PROGRAM([[
|
||||||
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#include <time.h>
|
||||||
|
]],[[
|
||||||
|
struct timespec ts;
|
||||||
|
(void)clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||||
|
]])
|
||||||
|
],[
|
||||||
|
AC_MSG_RESULT([yes])
|
||||||
|
AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC_RAW, 1,
|
||||||
|
[Define to 1 if you have the clock_gettime function and raw monotonic timer.])
|
||||||
|
],[
|
||||||
|
AC_MSG_RESULT([no])
|
||||||
|
])
|
||||||
|
fi
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
|
dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
|
||||||
dnl -------------------------------------------------
|
dnl -------------------------------------------------
|
||||||
|
|||||||
@ -1339,6 +1339,9 @@ dnl check for additional required libraries.
|
|||||||
dnl **********************************************************************
|
dnl **********************************************************************
|
||||||
CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
|
CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
|
||||||
|
|
||||||
|
dnl Check for even better option
|
||||||
|
CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC_RAW
|
||||||
|
|
||||||
dnl **********************************************************************
|
dnl **********************************************************************
|
||||||
dnl The preceding library checks are all potentially useful for test
|
dnl The preceding library checks are all potentially useful for test
|
||||||
dnl servers and libtest cases which require networking and clock_gettime
|
dnl servers and libtest cases which require networking and clock_gettime
|
||||||
|
|||||||
@ -58,7 +58,8 @@ struct curltime Curl_now(void)
|
|||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
|
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) || \
|
||||||
|
defined(HAVE_CLOCK_GETTIME_MONOTONIC_RAW)
|
||||||
|
|
||||||
struct curltime Curl_now(void)
|
struct curltime Curl_now(void)
|
||||||
{
|
{
|
||||||
@ -87,6 +88,19 @@ struct curltime Curl_now(void)
|
|||||||
have_clock_gettime = TRUE;
|
have_clock_gettime = TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_CLOCK_GETTIME_MONOTONIC_RAW
|
||||||
|
if(
|
||||||
|
#if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \
|
||||||
|
(HAVE_BUILTIN_AVAILABLE == 1)
|
||||||
|
have_clock_gettime &&
|
||||||
|
#endif
|
||||||
|
(0 == clock_gettime(CLOCK_MONOTONIC_RAW, &tsnow))) {
|
||||||
|
cnow.tv_sec = tsnow.tv_sec;
|
||||||
|
cnow.tv_usec = (unsigned int)(tsnow.tv_nsec / 1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
|
||||||
if(
|
if(
|
||||||
#if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \
|
#if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \
|
||||||
(HAVE_BUILTIN_AVAILABLE == 1)
|
(HAVE_BUILTIN_AVAILABLE == 1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user