configure: Cache result of pthread_condattr_setclock() check

Even if not using caching when running the configure script (-C) this
allows pre-defining the result by setting the environment variable
ss_cv_func_pthread_condattr_setclock_monotonic=yes|no|unknown
before/while running the script.

As the check requires running a test program this might be helpful
when cross-compiling to disable using monotonic time if
pthread_condattr_setclock() is defined but not actually usable with
CLOCK_MONOTONIC.

References #1502.
This commit is contained in:
Tobias Brunner 2016-06-16 17:57:37 +02:00
parent e827e78483
commit 8d79bfa831
1 changed files with 22 additions and 18 deletions

View File

@ -512,24 +512,28 @@ AC_COMPILE_IFELSE(
# check if pthread_condattr_setclock(CLOCK_MONOTONIC) is supported # check if pthread_condattr_setclock(CLOCK_MONOTONIC) is supported
saved_LIBS=$LIBS saved_LIBS=$LIBS
LIBS=$PTHREADLIB LIBS=$PTHREADLIB
AC_MSG_CHECKING([for pthread_condattr_setclock(CLOCK_MONOTONIC)]) AC_CACHE_CHECK([for pthread_condattr_setclock(CLOCK_MONOTONIC)],
AC_RUN_IFELSE( [ss_cv_func_pthread_condattr_setclock_monotonic],
[AC_LANG_SOURCE( [AC_RUN_IFELSE(
[[#include <pthread.h> [AC_LANG_SOURCE(
int main() { pthread_condattr_t attr; [[#include <pthread.h>
pthread_condattr_init(&attr); int main() { pthread_condattr_t attr;
return pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);}]])], pthread_condattr_init(&attr);
[AC_MSG_RESULT([yes]); return pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);}]])],
AC_DEFINE([HAVE_CONDATTR_CLOCK_MONOTONIC], [], [ss_cv_func_pthread_condattr_setclock_monotonic=yes],
[pthread_condattr_setclock supports CLOCK_MONOTONIC])], [ss_cv_func_pthread_condattr_setclock_monotonic=no],
[AC_MSG_RESULT([no])], # Check existence of pthread_condattr_setclock if cross-compiling
# Check existence of pthread_condattr_setclock if cross-compiling [AC_CHECK_FUNCS(pthread_condattr_setclock,
[AC_MSG_RESULT([unknown]); ss_cv_func_pthread_condattr_setclock_monotonic=unknown)]
AC_CHECK_FUNCS(pthread_condattr_setclock, )])
[AC_DEFINE([HAVE_CONDATTR_CLOCK_MONOTONIC], [], if test x$ss_cv_func_pthread_condattr_setclock_monotonic = xyes; then
[have pthread_condattr_setclock()])] AC_DEFINE([HAVE_CONDATTR_CLOCK_MONOTONIC], [],
)] [pthread_condattr_setclock supports CLOCK_MONOTONIC])
) elif test x$ss_cv_func_pthread_condattr_setclock_monotonic = xunknown; then
AC_DEFINE([HAVE_CONDATTR_CLOCK_MONOTONIC], [],
[have pthread_condattr_setclock()])
fi
# check if we actually are able to configure attributes on cond vars # check if we actually are able to configure attributes on cond vars
AC_CHECK_FUNCS(pthread_condattr_init) AC_CHECK_FUNCS(pthread_condattr_init)
# instead of pthread_condattr_setclock Android has this function # instead of pthread_condattr_setclock Android has this function