]> code.delx.au - pulseaudio/commitdiff
Create a new macro for checking compiler support for TLS.
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>
Fri, 8 Aug 2008 12:03:54 +0000 (14:03 +0200)
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>
Fri, 8 Aug 2008 13:09:38 +0000 (15:09 +0200)
Create a new macro that can be shared between projects to check for
__thread support by the compiler. This macro might come useful for
xine-lib too so I want to keep it separate for easier importing it
over.

Name the defined macro SUPPORT_TLS___THREAD to follow the same style
as the checks from attributes.m4.

configure.ac
m4/tls.m4 [new file with mode: 0644]
src/pulsecore/thread.h

index f56be997c6860845323bf29a7a21efbb343fb5a5..7c9da77cc150ba8f0883c9e99ffc2c734aae1cd2 100644 (file)
@@ -199,17 +199,7 @@ else
     esac
 fi
 
-AC_MSG_CHECKING([whether $CC knows __thread])
-AC_LANG_CONFTEST([static __thread int a = 6; int main() { a = 5; }])
-$CC conftest.c $CFLAGS -o conftest > /dev/null 2> /dev/null
-ret=$?
-rm -f conftest.o conftest
-if test $ret -eq 0 ; then
-    AC_DEFINE([HAVE_TLS_BUILTIN], 1, [Have __thread().])
-    AC_MSG_RESULT([yes])
-else
-    AC_MSG_RESULT([no])
-fi
+CC_CHECK_TLS
 
 AC_MSG_CHECKING([whether $CC knows _Bool])
 AC_LANG_CONFTEST([int main() { _Bool b; }])
diff --git a/m4/tls.m4 b/m4/tls.m4
new file mode 100644 (file)
index 0000000..3808f06
--- /dev/null
+++ b/m4/tls.m4
@@ -0,0 +1,17 @@
+AC_DEFUN([CC_CHECK_TLS], [
+  AC_CACHE_CHECK([whether $CC knows __thread for Thread-Local Storage],
+    cc_cv_tls___thread,
+    [AC_COMPILE_IFELSE(
+      AC_LANG_PROGRAM(
+        [[static __thread int a = 6;]],
+        [[a = 5;]]),
+      [cc_cv_tls___thread=yes],
+      [cc_cv_tls___thread=no])
+    ])
+  
+  AS_IF([test "x$cc_cv_tls___thread" = "xyes"],
+    [AC_DEFINE([SUPPORT_TLS___THREAD], 1,
+     [Define this if the compiler supports __thread for Thread-Local Storage])
+     $1],
+    [$2])
+])
index f3aca13e7b93c3efdc9308ecd30ec56baf7ad58c..87e850d67eae41221c92c595c6655fd70d1695ad 100644 (file)
@@ -86,7 +86,7 @@ void *pa_tls_set(pa_tls *t, void *userdata);
     }                                                                   \
     struct __stupid_useless_struct_to_allow_trailing_semicolon
 
-#ifdef HAVE_TLS_BUILTIN
+#ifdef SUPPORT_TLS___THREAD
 /* An optimized version of the above that requires no dynamic
  * allocation if the compiler supports __thread */
 #define PA_STATIC_TLS_DECLARE_NO_FREE(name)                             \