]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Detect the availability of _Thread_local using a configure check
authorCameron Cawley <ccawley2011@gmail.com>
Thu, 29 Sep 2022 18:30:31 +0000 (19:30 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 23 Oct 2022 13:01:26 +0000 (15:01 +0200)
CMakeLists.txt
configure
zbuild.h

index 2abeb69b6eb80b59681189ec86ddcc6323de5ff9..20ca1beb8d982d5801dcea2e3d161fc274534ea6 100644 (file)
@@ -386,6 +386,21 @@ if(HAVE_ATTRIBUTE_VISIBILITY_INTERNAL)
     add_definitions(-DHAVE_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
 #
@@ -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
 #
index 77005308c1959aab063cd9eac2acb16631146fb8..a64e1403ace4b924e9273c1c2293f4d59b2d7c66 100755 (executable)
--- 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) {
index 384dace34b1668216dad8847e9bb0bf46ed0a860..c96d48b31f07e643d58e4d3ff1c6ca4b4107f436 100644 (file)
--- 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