It was a long while back that I wondered && somehow ended up
volunteering to detect platform TLS support, + enable it in Mesa / the
X server if available.

I got distracted before finishing the X parts, but rebased the Mesa
parts, which are attached.

One thing I'm worried about is using an AC macro archive macro here;
it's GPL + an exception that "configure" (the output) is unrestricted.
I'm not sure that'll be kosher for Mesa.

OTOH, the macro is dead simple.

Comments?

-tom

From eec65ace0bbbb78b2b66e76ba79e9f67fa72d386 Mon Sep 17 00:00:00 2001
From: Tom Fogal <tfo...@alumni.unh.edu>
Date: Fri, 13 Nov 2009 21:19:18 -0700
Subject: [PATCH 1/2] RFC: Add macro to test for TLS from the AC macro archive.

This adds a macro to check for platform support of thread local
storage (TLS).

Note that the macro is under the GPL, meaning that this would
place Mesa's autoconf-based build system under the GPL as well.

The macro is placed in a separate file and included via
acinclude.m4.  This methodology allows for easy upgrades should
the macro ever be modified upstream.  The alternative is to place
the macro inline within acinclude.m4.
---
 acinclude.m4 |    2 +
 ax_tls.m4    |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 ax_tls.m4

diff --git a/acinclude.m4 b/acinclude.m4
index a5b389d..da6620d 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -117,3 +117,5 @@ if test "$enable_pic" != no; then
 fi
 AC_SUBST([PIC_FLAGS])
 ])# MESA_PIC_FLAGS
+
+m4_sinclude([ax_tls.m4])
diff --git a/ax_tls.m4 b/ax_tls.m4
new file mode 100644
index 0000000..7aa3383
--- /dev/null
+++ b/ax_tls.m4
@@ -0,0 +1,74 @@
+# ===========================================================================
+#             http://www.nongnu.org/autoconf-archive/ax_tls.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_TLS
+#
+# DESCRIPTION
+#
+#   Provides a test for the compiler support of thread local storage (TLS)
+#   extensions. Defines TLS if it is found. Currently only knows about GCC
+#   and MSVC. I think SunPro uses the same as GCC, and Borland apparently
+#   supports either.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Alan Woodland <aj...@aber.ac.uk>
+#
+#   This program is free software: you can redistribute it and/or modify it
+#   under the terms of the GNU General Public License as published by the
+#   Free Software Foundation, either version 3 of the License, or (at your
+#   option) any later version.
+#
+#   This program is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+#   Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License along
+#   with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#   As a special exception, the respective Autoconf Macro's copyright owner
+#   gives unlimited permission to copy, distribute and modify the configure
+#   scripts that are the output of Autoconf when processing the Macro. You
+#   need not follow the terms of the GNU General Public License when using
+#   or distributing such scripts, even though portions of the text of the
+#   Macro appear in them. The GNU General Public License (GPL) does govern
+#   all other use of the material that constitutes the Autoconf Macro.
+#
+#   This special exception to the GPL applies to versions of the Autoconf
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.
+
+AC_DEFUN([AX_TLS], [
+  AC_MSG_CHECKING(for thread local storage (TLS) class)
+  AC_CACHE_VAL(ac_cv_tls, [
+    ax_tls_keywords="__thread __declspec(thread) none"
+    for ax_tls_keyword in $ax_tls_keywords; do
+       case $ax_tls_keyword in
+          none) ac_cv_tls=none ; break ;;
+	  *)
+             AC_TRY_COMPILE(
+                [#include <stdlib.h>
+                 static void
+                 foo(void) {
+                 static ] $ax_tls_keyword [ int bar;
+                 exit(1);
+                 }],
+                 [],
+                 [ac_cv_tls=$ax_tls_keyword ; break],
+                 ac_cv_tls=none
+             )
+	  esac
+    done
+])
+
+  if test "$ac_cv_tls" != "none"; then
+    dnl AC_DEFINE([TLS], [], [If the compiler supports a TLS storage class define it to that here])
+    AC_DEFINE_UNQUOTED([TLS], $ac_cv_tls, [If the compiler supports a TLS storage class define it to that here])
+  fi
+  AC_MSG_RESULT($ac_cv_tls)
+])
-- 
1.7.0.2

From 5ccda10bd39bb89a3449bfabf2deb2dee54196bc Mon Sep 17 00:00:00 2001
From: Tom Fogal <tfo...@alumni.unh.edu>
Date: Fri, 13 Nov 2009 21:25:45 -0700
Subject: [PATCH 2/2] autoconf: Detect platform support for glX TLS.

Check for thread local storage support at build time.  If
supported, propagate the setting into Mesa's installed `gl.pc'
file, so that later builds of the X server can pick up on it.
---
 configs/autoconf.in |    2 +-
 configure.ac        |   19 ++++++++++++++-----
 src/mesa/Makefile   |    1 +
 src/mesa/gl.pc.in   |    1 +
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/configs/autoconf.in b/configs/autoconf.in
index f50fb7d..6724f3a 100644
--- a/configs/autoconf.in
+++ b/configs/autoconf.in
@@ -155,6 +155,6 @@ GLW_PC_LIB_PRIV = @GLW_PC_LIB_PRIV@
 GLW_PC_CFLAGS = @GLW_PC_CFLAGS@
 OSMESA_PC_REQ = @OSMESA_PC_REQ@
 OSMESA_PC_LIB_PRIV = @OSMESA_PC_LIB_PRIV@
-
 EGL_DRI2_CFLAGS = @EGL_DRI2_CFLAGS@
 EGL_DRI2_LIBS = @EGL_DRI2_LIBS@
+GLX_TLS = @GLX_TLS@
diff --git a/configure.ac b/configure.ac
index 35fbcd9..98dd877 100644
--- a/configure.ac
+++ b/configure.ac
@@ -670,14 +670,22 @@ if test "$mesa_driver" = xlib; then
     DEFINES="$DEFINES -DUSE_XSHM"
 fi
 
-dnl
-dnl More DRI setup
-dnl
+AX_TLS
 AC_ARG_ENABLE([glx-tls],
     [AS_HELP_STRING([--enable-glx-tls],
-        [enable TLS support in GLX @<:@default=disabled@:>@])],
+        [enable TLS support in GLX @<:@default=autodetect@:>@])],
     [GLX_USE_TLS="$enableval"],
-    [GLX_USE_TLS=no])
+    [GLX_USE_TLS=no
+     if test "${ac_cv_tls}" != "none"; then
+       GLX_USE_TLS=yes
+     fi]
+)
+AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
+
+dnl
+dnl More DRI setup
+dnl
+
 dnl Directory for DRI drivers
 AC_ARG_WITH([dri-driverdir],
     [AS_HELP_STRING([--with-dri-driverdir=DIR],
@@ -1423,6 +1431,7 @@ fi
     echo "        DRI driver dir:  $DRI_DRIVER_INSTALL_DIR"
 fi
 echo "        Use XCB:         $enable_xcb"
+echo "        glX TLS:         $GLX_USE_TLS"
 
 echo ""
 if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then
diff --git a/src/mesa/Makefile b/src/mesa/Makefile
index 8c0ebf8..fe0c6e3 100644
--- a/src/mesa/Makefile
+++ b/src/mesa/Makefile
@@ -105,6 +105,7 @@ gl_pcedit = sed \
 	-e 's,@GL_PC_REQ_PRIV@,$(GL_PC_REQ_PRIV),' \
 	-e 's,@GL_PC_LIB_PRIV@,$(GL_PC_LIB_PRIV),' \
 	-e 's,@GL_PC_CFLAGS@,$(GL_PC_CFLAGS),' \
+	-e 's,@GLX_TLS@,$(GLX_TLS),' \
 	-e 's,@GL_LIB@,$(GL_LIB),'
 
 gl.pc: gl.pc.in
diff --git a/src/mesa/gl.pc.in b/src/mesa/gl.pc.in
index 97b8659..2d3bc91 100644
--- a/src/mesa/gl.pc.in
+++ b/src/mesa/gl.pc.in
@@ -10,3 +10,4 @@ Version: @VERSION@
 Libs: -L${libdir} -...@gl_lib@
 Libs.private: @GL_PC_LIB_PRIV@
 Cflags: -I${includedir} @GL_PC_CFLAGS@
+glx_tls: @GLX_TLS@
-- 
1.7.0.2

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to