Skip to content

Commit 480e341

Browse files
committed
configure: Add flag for enabling thread_local.
- When aiming for glibc compatibility, don't use thread_local. - Add a flag --enable-threadlocal, which, when specified, will enable/disable thread_local regardless of the value of glibc_compat. - FreeBSD has a buggy thread_local, don't use it.
1 parent 149b347 commit 480e341

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

configure.ac

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ AC_ARG_ENABLE([glibc-back-compat],
194194
[use_glibc_compat=$enableval],
195195
[use_glibc_compat=no])
196196

197+
AC_ARG_ENABLE([threadlocal],
198+
[AS_HELP_STRING([--enable-threadlocal],
199+
[enable features that depend on the c++ thread_local keyword (currently just thread names in debug logs). (default is to enabled if there is platform support and glibc-back-compat is not enabled)])],
200+
[use_thread_local=$enableval],
201+
[use_thread_local=auto])
202+
197203
AC_ARG_ENABLE([asm],
198204
[AS_HELP_STRING([--disable-asm],
199205
[disable assembly routines (enabled by default)])],
@@ -827,42 +833,49 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([
827833
]
828834
)
829835

830-
TEMP_LDFLAGS="$LDFLAGS"
831-
LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
832-
AC_MSG_CHECKING([for thread_local support])
833-
AC_LINK_IFELSE([AC_LANG_SOURCE([
834-
#include <thread>
835-
static thread_local int foo = 0;
836-
static void run_thread() { foo++;}
837-
int main(){
838-
for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();}
839-
return foo;
840-
}
841-
])],
842-
[
843-
case $host in
844-
*mingw*)
845-
# mingw32's implementation of thread_local has also been shown to behave
846-
# erroneously under concurrent usage; see:
847-
# https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605
848-
AC_MSG_RESULT(no)
849-
;;
850-
*darwin*)
851-
# TODO enable thread_local on later versions of Darwin where it is
852-
# supported (per https://stackoverflow.com/a/29929949)
853-
AC_MSG_RESULT(no)
854-
;;
855-
*)
856-
AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.])
857-
AC_MSG_RESULT(yes)
858-
;;
859-
esac
860-
],
861-
[
862-
AC_MSG_RESULT(no)
863-
]
864-
)
865-
LDFLAGS="$TEMP_LDFLAGS"
836+
if test "x$use_thread_local" = xyes || { test "x$use_thread_local" = xauto && test "x$use_glibc_compat" = xno; }; then
837+
TEMP_LDFLAGS="$LDFLAGS"
838+
LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
839+
AC_MSG_CHECKING([for thread_local support])
840+
AC_LINK_IFELSE([AC_LANG_SOURCE([
841+
#include <thread>
842+
static thread_local int foo = 0;
843+
static void run_thread() { foo++;}
844+
int main(){
845+
for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();}
846+
return foo;
847+
}
848+
])],
849+
[
850+
case $host in
851+
*mingw*)
852+
# mingw32's implementation of thread_local has also been shown to behave
853+
# erroneously under concurrent usage; see:
854+
# https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605
855+
AC_MSG_RESULT(no)
856+
;;
857+
*darwin*)
858+
# TODO enable thread_local on later versions of Darwin where it is
859+
# supported (per https://stackoverflow.com/a/29929949)
860+
AC_MSG_RESULT(no)
861+
;;
862+
*freebsd*)
863+
# FreeBSD's implementation of thread_local is also buggy (per
864+
# https://groups.google.com/d/msg/bsdmailinglist/22ncTZAbDp4/Dii_pII5AwAJ)
865+
AC_MSG_RESULT(no)
866+
;;
867+
*)
868+
AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.])
869+
AC_MSG_RESULT(yes)
870+
;;
871+
esac
872+
],
873+
[
874+
AC_MSG_RESULT(no)
875+
]
876+
)
877+
LDFLAGS="$TEMP_LDFLAGS"
878+
fi
866879

867880
# Check for different ways of gathering OS randomness
868881
AC_MSG_CHECKING(for Linux getrandom syscall)

0 commit comments

Comments
 (0)