summaryrefslogtreecommitdiff
path: root/build/configure.ac.tls
blob: 881c919c4cece5439d6407a798c55aa38c7c237a (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
m4_define([libcairo_pthread_setspecific_program],[dnl
    #include <stdlib.h>
    #include <pthread.h>
    #include <stdio.h>

    static pthread_once_t once_control = PTHREAD_ONCE_INIT;
    static pthread_key_t key;

    static void
    make_key (void)
    {
        pthread_key_create (&key, NULL);
    }

    int
    main (int argc, char **argv)
    {
        void *value = NULL;

        if (pthread_once (&once_control, make_key) != 0)
        {
	   value = NULL;
        }
	else
        {
	    value = pthread_getspecific (key);
	    if (!value)
	    {
		value = malloc (100);
		pthread_setspecific (key, value);
	    }
	}

	printf ("%d, %p\n", argc, argv);
	return 0;
    }
}])

AC_DEFUN([CAIRO_CONFIGURE_TLS], [dnl
    have_tls=no
    AC_CACHE_VAL(ac_cv_tls, [
	ac_cv_tls=none
	keywords="__thread __declspec(thread)"
	for kw in $keywords ; do
	    AC_TRY_COMPILE([
	    #if defined(__MINGW32__) && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
	    #error This MinGW version has broken __thread support
	    #endif
	    #ifdef __OpenBSD__
	    #error OpenBSD has broken __thread support
	    #endif

	int $kw test;], [], [ac_cv_tls=$kw; break])
	done
    ])

    if test "$ac_cv_tls" != "none"; then
	have_tls=yes
	AC_DEFINE([CAIRO_HAS_TLS], 1, [Define to 1 if we have tls support])
	AC_DEFINE_UNQUOTED([TLS], $ac_cv_tls, [The compiler supported TLS storage class])
    fi

    dnl Set the output variables for CAIRO_ENABLE.
    use_tls="$have_tls"
    tls_REQUIRES=""
])

AC_DEFUN([CAIRO_CHECK_PTHREAD_SETSPECIFIC],[dnl
    CAIRO_CC_TRY_LINK_WITH_ENV_SILENT(
	[CFLAGS="$CFLAGS $2";
	LIBS="$LIBS $3"],
	[$4],
	[$1_CFLAGS="$2";
	$1_LIBS="$3";
	$5],
	[$1_CFLAGS="";
	$1_LIBS="";
	$6])
])

AC_DEFUN([CAIRO_CONFIGURE_PTHREAD_SETSPECIFIC],[dnl
    if test "x$PTHREAD_SETSPECIFIC_CFLAGS" = "x"; then
	PTHREAD_SETSPECIFIC_CFLAGS="-D_REENTRANT"
    fi

    if test "x$PTHREAD_SETSPECIFIC_LIBS" = "x"; then
	PTHREAD_SETSPECIFIC_LIBS="-lpthread"
    fi

    CAIRO_CHECK_PTHREAD_SETSPECIFIC(
	[pthread_setspecific], [$PTHREAD_SETSPECIFIC_CFLAGS], [$PTHREAD_SETSPECIFIC_LIBS],
	[libcairo_pthread_setspecific_program],
	[have_pthread_setspecific=yes],
	[have_pthread_setspecific=no])

    PTHREAD_SETSPECIFIC_CFLAGS=
    PTHREAD_SETSPECIFIC_LIBS=

    dnl Tell autoconf about the results.
    if test "x$have_pthread_setspecific" = "xyes"; then
	AC_DEFINE([CAIRO_HAS_PTHREAD_SETSPECIFIC], 1,
		  [Define to 1 if we have pthread_setspecific support])
    fi

    dnl Set the output variables for CAIRO_ENABLE.
    use_pthread_setspecific="$have_pthread_setspecific"
    pthread_setspecific_REQUIRES=""
])