summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCameron Cawley <ccawley2011@gmail.com>2022-09-29 19:30:31 +0100
committerHans Kristian Rosbach <hk-github@circlestorm.org>2022-10-23 15:01:26 +0200
commit0c118a14dd56d0484a8ca432cf801b9a6e6d024a (patch)
tree944ed76b642afb185b996be91a8f9632971d65f0
parentbaf0fd123411b6a6b864b5ac27d5a34bc9035909 (diff)
downloadProject-Tick-0c118a14dd56d0484a8ca432cf801b9a6e6d024a.tar.gz
Project-Tick-0c118a14dd56d0484a8ca432cf801b9a6e6d024a.zip
Detect the availability of _Thread_local using a configure check
-rw-r--r--CMakeLists.txt16
-rwxr-xr-xconfigure16
-rw-r--r--zbuild.h2
3 files changed, 33 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2abeb69b6e..20ca1beb8d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -387,6 +387,21 @@ if(HAVE_ATTRIBUTE_VISIBILITY_INTERNAL)
endif()
#
+# check for _Thread_local() support in the compiler
+#
+check_c_source_compiles(
+ "_Thread_local int test;
+ int main(void) {
+ (void)test;
+ return 0;
+ }"
+ HAVE_THREAD_LOCAL
+)
+if(HAVE_THREAD_LOCAL)
+ add_definitions(-DHAVE_THREAD_LOCAL)
+endif()
+
+#
# check for __builtin_ctz() support in the compiler
#
check_c_source_compiles(
@@ -401,6 +416,7 @@ check_c_source_compiles(
if(HAVE_BUILTIN_CTZ)
add_definitions(-DHAVE_BUILTIN_CTZ)
endif()
+
#
# check for __builtin_ctzll() support in the compiler
#
diff --git a/configure b/configure
index 77005308c1..a64e1403ac 100755
--- a/configure
+++ b/configure
@@ -942,6 +942,22 @@ EOF
fi
fi
+# Check for _Thread_local support in compiler
+cat > $test.c << EOF
+_Thread_local int test;
+int main(void) {
+ (void)test;
+ return 0;
+}
+EOF
+if try ${CC} ${CFLAGS} $test.c $LDSHAREDLIBC; then
+ echo "Checking for _Thread_local ... Yes." | tee -a configure.log
+ CFLAGS="$CFLAGS -DHAVE_THREAD_LOCAL"
+ SFLAGS="$SFLAGS -DHAVE_THREAD_LOCAL"
+else
+ echo "Checking for _Thread_local ... No." | tee -a configure.log
+fi
+
# Check for __builtin_ctz() support in compiler
cat > $test.c << EOF
int main(void) {
diff --git a/zbuild.h b/zbuild.h
index 384dace34b..c96d48b31f 100644
--- a/zbuild.h
+++ b/zbuild.h
@@ -27,7 +27,7 @@
/* Determine compiler support for TLS */
#ifndef Z_TLS
-# if defined(STDC11) && !defined(__STDC_NO_THREADS__)
+# ifdef HAVE_THREAD_LOCAL
# define Z_TLS _Thread_local
# elif defined(__GNUC__) || defined(__SUNPRO_C)
# define Z_TLS __thread