summaryrefslogtreecommitdiffstats
path: root/m4/fr_tls.m4
blob: 56ad7f273cf98c256abbb52a093e0c446ae9c158 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
dnl #
dnl #  Figure out which storage class specifier for Thread Local Storage is supported by the compiler
dnl #
AC_DEFUN([FR_TLS],
[
dnl #
dnl #  See if the compilation works with __thread, for thread-local storage
dnl #
  AC_MSG_CHECKING(for __thread support in compiler)
  AC_RUN_IFELSE(
    [AC_LANG_SOURCE(
      [[
        static __thread int val;
        int main(int argc, char **argv) {
          val = 0;
          return val;
        }
      ]])
    ],[have_tls=yes],[have_tls=no],[have_tls=no])
  AC_MSG_RESULT($have_tls)
  if test "x$have_tls" = "xyes"; then
    AC_DEFINE([TLS_STORAGE_CLASS],[__thread],[Define if the compiler supports a thread local storage class])
  fi

dnl #
dnl #  __declspec(thread) does exactly the same thing as __thread, but is supported by MSVS
dnl #
  if test "x$have_tls" = "xno"; then
    AC_MSG_CHECKING(for __declspec(thread) support in compiler)
    AC_RUN_IFELSE(
      [AC_LANG_SOURCE(
        [[
          static _Thread_local int val;
          int main(int argc, char **argv) {
            val = 0;
            return val;
          }
        ]])
      ],[have_tls=yes],[have_tls=no],[have_tls=no])
    AC_MSG_RESULT($have_tls)
    if test "x$have_tls" = "xyes"; then
      AC_DEFINE([TLS_STORAGE_CLASS],[__declspec(thread)],[Define if the compiler supports a thread local storage class])
    fi
  fi
dnl #
dnl #  _Thread_local does exactly the same thing as __thread, but it's standards compliant with C11.
dnl #  we, however, state we are only compliant with C99, so the compiler will probably emit warnings
dnl #  if we use it.  So save it as a last resort.
dnl #
  if test "x$have_tls" = "xno"; then
    AC_MSG_CHECKING(for _Thread_local support in compiler)
    AC_RUN_IFELSE(
      [AC_LANG_SOURCE(
        [[
          static _Thread_local int val;
          int main(int argc, char **argv) {
            val = 0;
            return val;
          }
        ]])
      ],[have_tls=yes],[have_tls=no],[have_tls=no])
    AC_MSG_RESULT($have_tls)
    if test "x$have_tls" = "xyes"; then
      AC_DEFINE([TLS_STORAGE_CLASS],[_Thread_local],[Define if the compiler supports a thread local storage class])
    fi
  fi
])