From f7f7e2cd340c088e82d09090eb275b98b34a9812 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 27 Nov 2017 17:08:27 -0500 Subject: [PATCH] threads: add a thread_local autoconf check --- configure.ac | 22 ++++++++++++++++++++++ src/sync.cpp | 3 +++ 2 files changed, 25 insertions(+) diff --git a/configure.ac b/configure.ac index 8e5561243..a05896ede 100644 --- a/configure.ac +++ b/configure.ac @@ -659,6 +659,28 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([ ] ) +TEMP_LDFLAGS="$LDFLAGS" +LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS" +AC_MSG_CHECKING([for thread_local support]) +AC_LINK_IFELSE([AC_LANG_SOURCE([ + #include + static thread_local int foo = 0; + static void run_thread() { foo++;} + int main(){ + for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();} + return foo; + } + ])], + [ + AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.]) + AC_MSG_RESULT(yes) + ], + [ + AC_MSG_RESULT(no) + ] +) +LDFLAGS="$TEMP_LDFLAGS" + # Check for different ways of gathering OS randomness AC_MSG_CHECKING(for Linux getrandom syscall) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include diff --git a/src/sync.cpp b/src/sync.cpp index 116533eb4..3f51383ea 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -11,6 +11,9 @@ #include #ifdef DEBUG_LOCKCONTENTION +#if !defined(HAVE_THREAD_LOCAL) +static_assert(false, "thread_local is not supported"); +#endif void PrintLockContention(const char* pszName, const char* pszFile, int nLine) { LogPrintf("LOCKCONTENTION: %s\n", pszName);