tizen 2.3.1 release
[framework/graphics/cairo.git] / build / configure.ac.tls
1 m4_define([libcairo_pthread_setspecific_program],[dnl
2     #include <stdlib.h>
3     #include <pthread.h>
4     #include <stdio.h>
5
6     static pthread_once_t once_control = PTHREAD_ONCE_INIT;
7     static pthread_key_t key;
8
9     static void
10     make_key (void)
11     {
12         pthread_key_create (&key, NULL);
13     }
14
15     int
16     main (int argc, char **argv)
17     {
18         void *value = NULL;
19
20         if (pthread_once (&once_control, make_key) != 0)
21         {
22            value = NULL;
23         }
24         else
25         {
26             value = pthread_getspecific (key);
27             if (!value)
28             {
29                 value = malloc (100);
30                 pthread_setspecific (key, value);
31             }
32         }
33
34         printf ("%d, %p\n", argc, argv);
35         return 0;
36     }
37 }])
38
39 AC_DEFUN([CAIRO_CONFIGURE_TLS], [dnl
40     have_tls=no
41     AC_CACHE_VAL(ac_cv_tls, [
42         ac_cv_tls=none
43         keywords="__thread __declspec(thread)"
44         for kw in $keywords ; do
45             AC_TRY_COMPILE([
46             #if defined(__MINGW32__) && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
47             #error This MinGW version has broken __thread support
48             #endif
49             #ifdef __OpenBSD__
50             #error OpenBSD has broken __thread support
51             #endif
52
53         int $kw test;], [], [ac_cv_tls=$kw; break])
54         done
55     ])
56
57     if test "$ac_cv_tls" != "none"; then
58         have_tls=yes
59         AC_DEFINE([CAIRO_HAS_TLS], 1, [Define to 1 if we have tls support])
60         AC_DEFINE_UNQUOTED([TLS], $ac_cv_tls, [The compiler supported TLS storage class])
61     fi
62
63     dnl Set the output variables for CAIRO_ENABLE.
64     use_tls="$have_tls"
65     tls_REQUIRES=""
66 ])
67
68 AC_DEFUN([CAIRO_CHECK_PTHREAD_SETSPECIFIC],[dnl
69     CAIRO_CC_TRY_LINK_WITH_ENV_SILENT(
70         [CFLAGS="$CFLAGS $2";
71         LIBS="$LIBS $3"],
72         [$4],
73         [$1_CFLAGS="$2";
74         $1_LIBS="$3";
75         $5],
76         [$1_CFLAGS="";
77         $1_LIBS="";
78         $6])
79 ])
80
81 AC_DEFUN([CAIRO_CONFIGURE_PTHREAD_SETSPECIFIC],[dnl
82     if test "x$PTHREAD_SETSPECIFIC_CFLAGS" = "x"; then
83         PTHREAD_SETSPECIFIC_CFLAGS="-D_REENTRANT"
84     fi
85
86     if test "x$PTHREAD_SETSPECIFIC_LIBS" = "x"; then
87         PTHREAD_SETSPECIFIC_LIBS="-lpthread"
88     fi
89
90     CAIRO_CHECK_PTHREAD_SETSPECIFIC(
91         [pthread_setspecific], [$PTHREAD_SETSPECIFIC_CFLAGS], [$PTHREAD_SETSPECIFIC_LIBS],
92         [libcairo_pthread_setspecific_program],
93         [have_pthread_setspecific=yes],
94         [have_pthread_setspecific=no])
95
96     PTHREAD_SETSPECIFIC_CFLAGS=
97     PTHREAD_SETSPECIFIC_LIBS=
98
99     dnl Tell autoconf about the results.
100     if test "x$have_pthread_setspecific" = "xyes"; then
101         AC_DEFINE([CAIRO_HAS_PTHREAD_SETSPECIFIC], 1,
102                   [Define to 1 if we have pthread_setspecific support])
103     fi
104
105     dnl Set the output variables for CAIRO_ENABLE.
106     use_pthread_setspecific="$have_pthread_setspecific"
107     pthread_setspecific_REQUIRES=""
108 ])