Skip to content

Commit f7f7e2c

Browse files
theunitjps
authored andcommitted
threads: add a thread_local autoconf check
1 parent bba9bd0 commit f7f7e2c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

configure.ac

+22
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,28 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([
659659
]
660660
)
661661

662+
TEMP_LDFLAGS="$LDFLAGS"
663+
LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
664+
AC_MSG_CHECKING([for thread_local support])
665+
AC_LINK_IFELSE([AC_LANG_SOURCE([
666+
#include <thread>
667+
static thread_local int foo = 0;
668+
static void run_thread() { foo++;}
669+
int main(){
670+
for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();}
671+
return foo;
672+
}
673+
])],
674+
[
675+
AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.])
676+
AC_MSG_RESULT(yes)
677+
],
678+
[
679+
AC_MSG_RESULT(no)
680+
]
681+
)
682+
LDFLAGS="$TEMP_LDFLAGS"
683+
662684
# Check for different ways of gathering OS randomness
663685
AC_MSG_CHECKING(for Linux getrandom syscall)
664686
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>

src/sync.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <stdio.h>
1212

1313
#ifdef DEBUG_LOCKCONTENTION
14+
#if !defined(HAVE_THREAD_LOCAL)
15+
static_assert(false, "thread_local is not supported");
16+
#endif
1417
void PrintLockContention(const char* pszName, const char* pszFile, int nLine)
1518
{
1619
LogPrintf("LOCKCONTENTION: %s\n", pszName);

0 commit comments

Comments
 (0)