diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/m4/common/efl_threads.m4 | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/libraries/eina/m4/common/efl_threads.m4 b/libraries/eina/m4/common/efl_threads.m4 new file mode 100644 index 0000000..a761d51 --- /dev/null +++ b/libraries/eina/m4/common/efl_threads.m4 | |||
@@ -0,0 +1,219 @@ | |||
1 | dnl Copyright (C) 2010 Vincent Torri <vtorri at univ-evry dot fr> | ||
2 | dnl rwlock code added by Mike Blumenkrantz <mike at zentific dot com> | ||
3 | dnl This code is public domain and can be freely used or copied. | ||
4 | |||
5 | dnl Macro that check if POSIX or Win32 threads library is available or not. | ||
6 | |||
7 | dnl Usage: EFL_CHECK_THREADS(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]) | ||
8 | dnl Call AC_SUBST(EFL_PTHREAD_CFLAGS) | ||
9 | dnl Call AC_SUBST(EFL_PTHREAD_LIBS) | ||
10 | dnl Defines EFL_HAVE_POSIX_THREADS or EFL_HAVE_WIN32_THREADS, and EFL_HAVE_THREADS | ||
11 | |||
12 | AC_DEFUN([EFL_CHECK_THREADS], | ||
13 | [ | ||
14 | |||
15 | dnl configure option | ||
16 | |||
17 | AC_ARG_ENABLE([posix-threads], | ||
18 | [AC_HELP_STRING([--disable-posix-threads], [enable POSIX threads code @<:@default=auto@:>@])], | ||
19 | [ | ||
20 | if test "x${enableval}" = "xyes" ; then | ||
21 | _efl_enable_posix_threads="yes" | ||
22 | else | ||
23 | _efl_enable_posix_threads="no" | ||
24 | fi | ||
25 | ], | ||
26 | [_efl_enable_posix_threads="auto"]) | ||
27 | |||
28 | AC_MSG_CHECKING([whether to build POSIX threads code]) | ||
29 | AC_MSG_RESULT([${_efl_enable_posix_threads}]) | ||
30 | |||
31 | AC_ARG_ENABLE([win32-threads], | ||
32 | [AC_HELP_STRING([--disable-win32-threads], [enable Win32 threads code @<:@default=no@:>@])], | ||
33 | [ | ||
34 | if test "x${enableval}" = "xyes" ; then | ||
35 | _efl_enable_win32_threads="yes" | ||
36 | else | ||
37 | _efl_enable_win32_threads="no" | ||
38 | fi | ||
39 | ], | ||
40 | [_efl_enable_win32_threads="no"]) | ||
41 | |||
42 | AC_MSG_CHECKING([whether to build Windows threads code]) | ||
43 | AC_MSG_RESULT([${_efl_enable_win32_threads}]) | ||
44 | |||
45 | dnl | ||
46 | dnl * no + no | ||
47 | dnl * yes + no : win32: error, other : pthread | ||
48 | dnl * yes + yes : win32 : wthread, other : pthread | ||
49 | dnl * no + yes : win32 : wthread, other : error | ||
50 | |||
51 | if test "x${_efl_enable_posix_threads}" = "xyes" && test "x${_efl_enable_win32_threads}" = "xyes" ; then | ||
52 | case "$host_os" in | ||
53 | mingw*) | ||
54 | _efl_enable_posix_threads=no | ||
55 | ;; | ||
56 | *) | ||
57 | _efl_enable_win32_threads=no | ||
58 | ;; | ||
59 | esac | ||
60 | fi | ||
61 | |||
62 | if test "x${_efl_enable_win32_threads}" = "xyes" ; then | ||
63 | case "$host_os" in | ||
64 | mingw*) | ||
65 | ;; | ||
66 | *) | ||
67 | AC_MSG_ERROR([Win32 threads support requested but non Windows system found.]) | ||
68 | ;; | ||
69 | esac | ||
70 | fi | ||
71 | |||
72 | if test "x${_efl_enable_posix_threads}" = "xyes" ; then | ||
73 | case "$host_os" in | ||
74 | mingw*) | ||
75 | AC_MSG_ERROR([POSIX threads support requested but Windows system found.]) | ||
76 | ;; | ||
77 | *) | ||
78 | ;; | ||
79 | esac | ||
80 | fi | ||
81 | |||
82 | dnl check if the compiler supports POSIX threads | ||
83 | |||
84 | case "$host_os" in | ||
85 | mingw*) | ||
86 | ;; | ||
87 | solaris*) | ||
88 | _efl_threads_cflags="-mt" | ||
89 | _efl_threads_libs="-mt" | ||
90 | ;; | ||
91 | *) | ||
92 | _efl_threads_cflags="-pthread" | ||
93 | _efl_threads_libs="-pthread" | ||
94 | ;; | ||
95 | esac | ||
96 | |||
97 | _efl_have_posix_threads="no" | ||
98 | _efl_have_win32_threads="no" | ||
99 | |||
100 | if test "x${_efl_enable_posix_threads}" = "xyes" || test "x${_efl_enable_posix_threads}" = "xauto" ; then | ||
101 | |||
102 | SAVE_CFLAGS=${CFLAGS} | ||
103 | CFLAGS="${CFLAGS} ${_efl_threads_cflags}" | ||
104 | SAVE_LIBS=${LIBS} | ||
105 | LIBS="${LIBS} ${_efl_threads_libs}" | ||
106 | AC_LINK_IFELSE( | ||
107 | [AC_LANG_PROGRAM([[ | ||
108 | #include <pthread.h> | ||
109 | ]], | ||
110 | [[ | ||
111 | pthread_t id; | ||
112 | id = pthread_self(); | ||
113 | ]])], | ||
114 | [_efl_have_posix_threads="yes"], | ||
115 | [_efl_have_posix_threads="no"]) | ||
116 | CFLAGS=${SAVE_CFLAGS} | ||
117 | LIBS=${SAVE_LIBS} | ||
118 | |||
119 | fi | ||
120 | |||
121 | AC_MSG_CHECKING([whether system support POSIX threads]) | ||
122 | AC_MSG_RESULT([${_efl_have_posix_threads}]) | ||
123 | if test "$x{_efl_enable_posix_threads}" = "xyes" && test "x${_efl_have_posix_threads}" = "xno"; then | ||
124 | AC_MSG_ERROR([POSIX threads support requested but not found.]) | ||
125 | fi | ||
126 | |||
127 | EFL_PTHREAD_CFLAGS="" | ||
128 | EFL_PTHREAD_LIBS="" | ||
129 | if test "x${_efl_have_posix_threads}" = "xyes" ; then | ||
130 | EFL_PTHREAD_CFLAGS=${_efl_threads_cflags} | ||
131 | EFL_PTHREAD_LIBS=${_efl_threads_libs} | ||
132 | fi | ||
133 | |||
134 | AC_SUBST(EFL_PTHREAD_CFLAGS) | ||
135 | AC_SUBST(EFL_PTHREAD_LIBS) | ||
136 | |||
137 | _efl_enable_on_off_threads="no" | ||
138 | AC_ARG_ENABLE([on-off-threads], | ||
139 | [AC_HELP_STRING([--enable-on-off-threads], [only turn this on if you know what you are doing, and don't complain if the world freeze])], | ||
140 | [_efl_enable_on_off_threads="${enableval}"]) | ||
141 | |||
142 | have_on_off_threads="no" | ||
143 | if test "x${_efl_enable_on_off_threads}" = "xyes"; then | ||
144 | have_on_off_threads="yes" | ||
145 | AC_DEFINE([EFL_ON_OFF_THREADS], [1], [make it possible to disable all locks]) | ||
146 | fi | ||
147 | AC_MSG_CHECKING([whether to turn on/off threads lock on demand]) | ||
148 | AC_MSG_RESULT([${_efl_enable_on_off_threads}]) | ||
149 | |||
150 | _efl_enable_debug_threads="no" | ||
151 | AC_ARG_ENABLE([debug-threads], | ||
152 | [AC_HELP_STRING([--enable-debug-threads], [disable assert when you forgot to call eina_threads_init])], | ||
153 | [_efl_enable_debug_threads="${enableval}"]) | ||
154 | |||
155 | have_debug_threads="no" | ||
156 | if test "x${_efl_have_posix_threads}" = "xyes" -a "x${_efl_enable_debug_threads}" = "xyes"; then | ||
157 | have_debug_threads="yes" | ||
158 | AC_DEFINE([EFL_DEBUG_THREADS], [1], [Assert when forgot to call eina_threads_init]) | ||
159 | fi | ||
160 | |||
161 | if test "x${_efl_have_posix_threads}" = "xyes" ; then | ||
162 | AC_DEFINE([EFL_HAVE_POSIX_THREADS], [1], [Define to mention that POSIX threads are supported]) | ||
163 | fi | ||
164 | |||
165 | if test "x${_efl_enable_win32_threads}" = "xyes" ; then | ||
166 | _efl_have_win32_threads="yes" | ||
167 | AC_DEFINE([EFL_HAVE_WIN32_THREADS], [1], [Define to mention that Win32 threads are supported]) | ||
168 | fi | ||
169 | |||
170 | if test "x${_efl_have_posix_threads}" = "xyes" || test "x${_efl_have_win32_threads}" = "xyes" ; then | ||
171 | AC_DEFINE([EFL_HAVE_THREADS], [1], [Define to mention that POSIX or Win32 threads are supported]) | ||
172 | fi | ||
173 | |||
174 | AS_IF([test "x$_efl_have_posix_threads" = "xyes" || test "x$_efl_have_win32_threads" = "xyes"], [$1], [$2]) | ||
175 | ]) | ||
176 | |||
177 | dnl Usage: EFL_CHECK_SPINLOCK(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]) | ||
178 | dnl Defines EFL_HAVE_POSIX_THREADS_SPINLOCK | ||
179 | AC_DEFUN([EFL_CHECK_SPINLOCK], | ||
180 | [ | ||
181 | |||
182 | dnl check if the compiler supports pthreads spinlock | ||
183 | |||
184 | _efl_have_posix_threads_spinlock="no" | ||
185 | |||
186 | if test "x${_efl_have_posix_threads}" = "xyes" ; then | ||
187 | |||
188 | SAVE_CFLAGS=${CFLAGS} | ||
189 | CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}" | ||
190 | SAVE_LIBS=${LIBS} | ||
191 | LIBS="${LIBS} ${EFL_PTHREAD_LIBS}" | ||
192 | AC_LINK_IFELSE( | ||
193 | [AC_LANG_PROGRAM([[ | ||
194 | #include <pthread.h> | ||
195 | ]], | ||
196 | [[ | ||
197 | pthread_spinlock_t lock; | ||
198 | int res; | ||
199 | res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE); | ||
200 | ]])], | ||
201 | [_efl_have_posix_threads_spinlock="yes"], | ||
202 | [_efl_have_posix_threads_spinlock="no"]) | ||
203 | CFLAGS=${SAVE_CFLAGS} | ||
204 | LIBS=${SAVE_LIBS} | ||
205 | |||
206 | fi | ||
207 | |||
208 | AC_MSG_CHECKING([whether to build POSIX threads spinlock code]) | ||
209 | AC_MSG_RESULT([${_efl_have_posix_threads_spinlock}]) | ||
210 | if test "x${_efl_enable_posix_threads}" = "xyes" && test "x${_efl_have_posix_threads_spinlock}" = "xno" ; then | ||
211 | AC_MSG_WARN([POSIX threads support requested but spinlocks are not supported]) | ||
212 | fi | ||
213 | |||
214 | if test "x${_efl_have_posix_threads_spinlock}" = "xyes" ; then | ||
215 | AC_DEFINE([EFL_HAVE_POSIX_THREADS_SPINLOCK], [1], [Define to mention that POSIX threads spinlocks are supported]) | ||
216 | fi | ||
217 | AS_IF([test "x$_efl_have_posix_threads_spinlock" = "xyes"], [$1], [$2]) | ||
218 | ]) | ||
219 | |||