Skip to content

Commit 66e4a6f

Browse files
committed
Add Autotools support for C11 threads.
If multithreading is not explicitly disabled, and if pthread is not detected, enable C11 threads support as a fallback. We still default to pthread as this is the more conservative and backwards-compatible approach for older POSIX systems. Using C11 threads might imply using pthreads under the hood, and might require linking additional pthread libraries, which a simple check for threads.h will not enable. AX_PTHREAD however does that, and it is thus the safer choice. configure output is changed to display "C11 threads" or "pthread", instead of just "yes" when multithreading is enabled.
1 parent 2ac5c3b commit 66e4a6f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

configure.ac

+17-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ AM_PROG_CC_C_O
5353
AC_C_INLINE
5454
AC_C_TYPEOF
5555

56-
AC_CHECK_HEADERS([stdint.h stdbool.h inttypes.h byteswap.h sys/auxv.h sys/param.h sys/ioctl.h sys/time.h termios.h x86intrin.h cpuid.h arm_neon.h])
56+
AC_CHECK_HEADERS([stdint.h stdbool.h inttypes.h byteswap.h sys/auxv.h sys/param.h sys/ioctl.h sys/time.h termios.h x86intrin.h cpuid.h arm_neon.h threads.h])
5757

5858
if test "x$ac_cv_header_stdint_h" != xyes -o "x$ac_cv_header_stdbool_h" != xyes; then
5959
AC_MSG_ERROR("Header stdint.h and/or stdbool.h not found")
@@ -379,15 +379,21 @@ HAVE_PTHREAD=no
379379
if test "x$enable_multithreading" != "xno" ; then
380380
AX_PTHREAD([
381381
HAVE_PTHREAD=yes
382-
AC_DEFINE(HAVE_PTHREAD,1,[Define if pthread is enabled])
382+
AC_DEFINE([HAVE_PTHREAD],1,[Define if multithreading is enable and pthread is available])
383383
LIBS="$PTHREAD_LIBS $LIBS"
384384
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
385385
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
386386
CC="$PTHREAD_CC"
387387
CXX="$PTHREAD_CXX"
388388
],[HAVE_PTHREAD=no])
389-
if test "x${HAVE_PTHREAD}" = "xno"; then
390-
AC_MSG_WARN("pthread support, needed for multithreading, is not found")
389+
if test "x${HAVE_PTHREAD}" = "xno" -a "x$ac_cv_header_threads_h" = "xyes"; then
390+
HAVE_C11THREADS=yes
391+
AC_DEFINE([HAVE_C11THREADS],1,[Define if multithreading is enable and <threads.h> is available])
392+
else
393+
HAVE_C11THREADS=no
394+
fi
395+
if test "x${HAVE_PTHREAD}" = "xno" -a "x${HAVE_C11THREADS}" = "xno"; then
396+
AC_MSG_WARN("pthread or C11 threads support, needed for multithreading, are not found")
391397
fi
392398
fi
393399

@@ -616,7 +622,13 @@ fi
616622
echo " Compiler is Clang : ....................... ${xiph_cv_c_compiler_clang}"
617623
echo " Asm optimizations : ....................... ${asm_optimisation}"
618624
echo " Ogg/FLAC support : ........................ ${have_ogg}"
619-
echo " Multithreading : ........................ ${HAVE_PTHREAD}"
625+
if test "x${HAVE_C11THREADS}" = "xyes" ; then
626+
echo " Multithreading : ........................ C11 threads"
627+
elif test "x${HAVE_PTHREAD}" = "xyes" ; then
628+
echo " Multithreading : ........................ pthread"
629+
else
630+
echo " Multithreading : ........................ no"
631+
fi
620632
echo " Stack protector : ........................ ${enable_stack_smash_protection}"
621633
echo " Fuzzing support (Clang only) : ............ ${have_oss_fuzzers}"
622634
echo

0 commit comments

Comments
 (0)