1# ===========================================================================
2#             http://www.nongnu.org/autoconf-archive/ax_tls.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_TLS
8#
9# DESCRIPTION
10#
11#   Provides a test for the compiler support of thread local storage (TLS)
12#   extensions. Defines TLS if it is found. Currently only knows about GCC
13#   and MSVC. I think SunPro uses the same as GCC, and Borland apparently
14#   supports either.
15#
16# LICENSE
17#
18#   Copyright (c) 2008 Alan Woodland <ajw05@aber.ac.uk>
19#
20#   This program is free software: you can redistribute it and/or modify it
21#   under the terms of the GNU General Public License as published by the
22#   Free Software Foundation, either version 3 of the License, or (at your
23#   option) any later version.
24#
25#   This program is distributed in the hope that it will be useful, but
26#   WITHOUT ANY WARRANTY; without even the implied warranty of
27#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
28#   Public License for more details.
29#
30#   You should have received a copy of the GNU General Public License along
31#   with this program. If not, see <http://www.gnu.org/licenses/>.
32#
33#   As a special exception, the respective Autoconf Macro's copyright owner
34#   gives unlimited permission to copy, distribute and modify the configure
35#   scripts that are the output of Autoconf when processing the Macro. You
36#   need not follow the terms of the GNU General Public License when using
37#   or distributing such scripts, even though portions of the text of the
38#   Macro appear in them. The GNU General Public License (GPL) does govern
39#   all other use of the material that constitutes the Autoconf Macro.
40#
41#   This special exception to the GPL applies to versions of the Autoconf
42#   Macro released by the Autoconf Archive. When you make and distribute a
43#   modified version of the Autoconf Macro, you may extend this special
44#   exception to the GPL to apply to your modified version as well.
45
46AC_DEFUN([AX_TLS], [
47  AC_MSG_CHECKING(for thread local storage specifier)
48  AC_CACHE_VAL(ac_cv_tls, [
49    ax_tls_keywords="__thread __declspec(thread) none"
50    for ax_tls_keyword in $ax_tls_keywords; do
51       case $ax_tls_keyword in
52          none) ac_cv_tls=none ; break ;;
53	  *)
54             # MPICH2 modification: This was an AC_TRY_COMPILE before, but
55             # Darwin with non-standard compilers will accept __thread at
56             # compile time but fail to link due to an undefined
57             # "__emutls_get_address" symbol unless -lgcc_eh is added to the
58             # link line.
59             AC_LINK_IFELSE(
60                 [AC_LANG_PROGRAM([$ax_tls_keyword int bar = 5;],[++bar;])],
61                 [ac_cv_tls=$ax_tls_keyword ; break],
62                 [ac_cv_tls=none])
63          esac
64    done
65])
66
67  if test "$ac_cv_tls" != "none"; then
68    # MPICH2 modification: this was "TLS" before instead of
69    # "MPIU_TLS_SPECIFIER", but TLS had a reasonably high chance of conflicting
70    # with a system library.
71    AC_DEFINE_UNQUOTED([MPIU_TLS_SPECIFIER], $ac_cv_tls, [If the compiler supports a TLS storage class define it to that here])
72  fi
73  AC_MSG_RESULT($ac_cv_tls)
74])
75