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.
5 dnl Macro that check if POSIX or Win32 threads library is available or not.
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
12 AC_DEFUN([EFL_CHECK_THREADS],
17 AC_ARG_ENABLE([posix-threads],
18 [AC_HELP_STRING([--disable-posix-threads], [enable POSIX threads code @<:@default=auto@:>@])],
20 if test "x${enableval}" = "xyes" ; then
21 _efl_enable_posix_threads="yes"
23 _efl_enable_posix_threads="no"
26 [_efl_enable_posix_threads="auto"])
28 AC_MSG_CHECKING([whether to build POSIX threads code])
29 AC_MSG_RESULT([${_efl_enable_posix_threads}])
31 AC_ARG_ENABLE([win32-threads],
32 [AC_HELP_STRING([--disable-win32-threads], [enable Win32 threads code @<:@default=no@:>@])],
34 if test "x${enableval}" = "xyes" ; then
35 _efl_enable_win32_threads="yes"
37 _efl_enable_win32_threads="no"
40 [_efl_enable_win32_threads="no"])
42 AC_MSG_CHECKING([whether to build Windows threads code])
43 AC_MSG_RESULT([${_efl_enable_win32_threads}])
47 dnl * yes + no : win32: error, other : pthread
48 dnl * yes + yes : win32 : wthread, other : pthread
49 dnl * no + yes : win32 : wthread, other : error
51 if test "x${_efl_enable_posix_threads}" = "xyes" && test "x${_efl_enable_win32_threads}" = "xyes" ; then
54 _efl_enable_posix_threads=no
57 _efl_enable_win32_threads=no
62 if test "x${_efl_enable_win32_threads}" = "xyes" ; then
67 AC_MSG_ERROR([Win32 threads support requested but non Windows system found.])
72 if test "x${_efl_enable_posix_threads}" = "xyes" ; then
75 AC_MSG_ERROR([POSIX threads support requested but Windows system found.])
82 dnl check if the compiler supports POSIX threads
88 _efl_threads_cflags="-mt"
89 _efl_threads_libs="-mt"
92 _efl_threads_cflags="-pthread"
93 _efl_threads_libs="-pthread"
97 _efl_have_posix_threads="no"
98 _efl_have_win32_threads="no"
100 if test "x${_efl_enable_posix_threads}" = "xyes" || test "x${_efl_enable_posix_threads}" = "xauto" ; then
102 SAVE_CFLAGS=${CFLAGS}
103 CFLAGS="${CFLAGS} ${_efl_threads_cflags}"
105 LIBS="${LIBS} ${_efl_threads_libs}"
114 [_efl_have_posix_threads="yes"],
115 [_efl_have_posix_threads="no"])
116 CFLAGS=${SAVE_CFLAGS}
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.])
127 EFL_PTHREAD_CFLAGS=""
129 if test "x${_efl_have_posix_threads}" = "xyes" ; then
130 EFL_PTHREAD_CFLAGS=${_efl_threads_cflags}
131 EFL_PTHREAD_LIBS=${_efl_threads_libs}
134 AC_SUBST(EFL_PTHREAD_CFLAGS)
135 AC_SUBST(EFL_PTHREAD_LIBS)
137 _efl_enable_debug_threads="no"
138 AC_ARG_ENABLE([debug-threads],
139 [AC_HELP_STRING([--enable-debug-threads], [disable assert when you forgot to call eina_threads_init])],
140 [_efl_enable_debug_threads="${enableval}"])
142 have_debug_threads="no"
143 if test "x${_efl_have_posix_threads}" = "xyes" -a "x${_efl_enable_debug_threads}" = "xyes"; then
144 have_debug_threads="yes"
145 AC_DEFINE([EFL_DEBUG_THREADS], [1], [Assert when forgot to call eina_threads_init])
148 if test "x${_efl_have_posix_threads}" = "xyes" ; then
149 AC_DEFINE([EFL_HAVE_POSIX_THREADS], [1], [Define to mention that POSIX threads are supported])
152 if test "x${_efl_enable_win32_threads}" = "xyes" ; then
153 _efl_have_win32_threads="yes"
154 AC_DEFINE([EFL_HAVE_WIN32_THREADS], [1], [Define to mention that Win32 threads are supported])
157 if test "x${_efl_have_posix_threads}" = "xyes" || test "x${_efl_have_win32_threads}" = "xyes" ; then
158 AC_DEFINE([EFL_HAVE_THREADS], [1], [Define to mention that POSIX or Win32 threads are supported])
161 AS_IF([test "x$_efl_have_posix_threads" = "xyes" || test "x$_efl_have_win32_threads" = "xyes"], [$1], [$2])
164 dnl Usage: EFL_CHECK_SPINLOCK(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
165 dnl Defines EFL_HAVE_POSIX_THREADS_SPINLOCK
166 AC_DEFUN([EFL_CHECK_SPINLOCK],
169 dnl check if the compiler supports pthreads spinlock
171 _efl_have_posix_threads_spinlock="no"
173 if test "x${_efl_have_posix_threads}" = "xyes" ; then
175 SAVE_CFLAGS=${CFLAGS}
176 CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}"
178 LIBS="${LIBS} ${EFL_PTHREAD_LIBS}"
184 pthread_spinlock_t lock;
186 res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
188 [_efl_have_posix_threads_spinlock="yes"],
189 [_efl_have_posix_threads_spinlock="no"])
190 CFLAGS=${SAVE_CFLAGS}
195 AC_MSG_CHECKING([whether to build POSIX threads spinlock code])
196 AC_MSG_RESULT([${_efl_have_posix_threads_spinlock}])
197 if test "x${_efl_enable_posix_threads}" = "xyes" && test "x${_efl_have_posix_threads_spinlock}" = "xno" ; then
198 AC_MSG_WARN([POSIX threads support requested but spinlocks are not supported])
201 if test "x${_efl_have_posix_threads_spinlock}" = "xyes" ; then
202 AC_DEFINE([EFL_HAVE_POSIX_THREADS_SPINLOCK], [1], [Define to mention that POSIX threads spinlocks are supported])
204 AS_IF([test "x$_efl_have_posix_threads_spinlock" = "xyes"], [$1], [$2])