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],
15 dnl Generic thread detection
20 _efl_enable_posix_threads="no"
21 _efl_have_posix_threads="no"
22 _efl_have_win32_threads="no"
26 _efl_have_win32_threads="yes"
27 AC_DEFINE([EFL_HAVE_WIN32_THREADS], [1], [Define to mention that Win32 threads are supported])
28 AC_DEFINE([EFL_HAVE_THREADS], [1], [Define to mention that POSIX or Win32 threads are supported])
31 _efl_enable_posix_threads="yes"
32 _efl_threads_cflags="-D_REENTRANT"
33 _efl_threads_libs="-lpthread"
37 dnl check if the compiler supports POSIX threads
40 if test "x${_efl_enable_posix_threads}" = "xyes" ; then
43 CFLAGS="${CFLAGS} ${_efl_threads_cflags}"
45 LIBS="${LIBS} ${_efl_threads_libs}"
55 _efl_have_posix_threads="yes"
56 AC_DEFINE([EFL_HAVE_POSIX_THREADS], [1], [Define to mention that POSIX threads are supported])
57 AC_DEFINE([EFL_HAVE_THREADS], [1], [Define to mention that POSIX or Win32 threads are supported])
58 EFL_PTHREAD_CFLAGS=${_efl_threads_cflags}
59 EFL_PTHREAD_LIBS=${_efl_threads_libs}
61 [_efl_have_posix_threads="no"])
67 AC_MSG_CHECKING([which threads API is used])
68 if test "x${_efl_have_posix_threads}" = "xyes" ; then
69 efl_have_threads="POSIX"
71 if test "x${_efl_have_win32_threads}" = "xyes" ; then
72 efl_have_threads="Windows"
77 AC_MSG_RESULT([${efl_have_threads}])
79 AC_SUBST(EFL_PTHREAD_CFLAGS)
80 AC_SUBST(EFL_PTHREAD_LIBS)
82 dnl check if the compiler supports pthreads spinlock
84 efl_have_posix_threads_spinlock="no"
86 if test "x${_efl_have_posix_threads}" = "xyes" ; then
89 CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}"
91 LIBS="${LIBS} ${EFL_PTHREAD_LIBS}"
97 pthread_spinlock_t lock;
99 res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
101 [efl_have_posix_threads_spinlock="yes"],
102 [efl_have_posix_threads_spinlock="no"])
103 CFLAGS=${SAVE_CFLAGS}
108 AC_MSG_CHECKING([whether to build POSIX threads spinlock code])
109 AC_MSG_RESULT([${efl_have_posix_threads_spinlock}])
111 if test "x${efl_have_posix_threads_spinlock}" = "xyes" ; then
112 AC_DEFINE([EFL_HAVE_POSIX_THREADS_SPINLOCK], [1], [Define to mention that POSIX threads spinlocks are supported])
115 dnl Check ON-OFF threads
117 _efl_enable_on_off_threads="no"
118 AC_ARG_ENABLE([on-off-threads],
119 [AC_HELP_STRING([--enable-on-off-threads], [only turn this on if you know what you are doing, and do not complain if the world freeze])],
120 [_efl_enable_on_off_threads="${enableval}"])
122 efl_have_on_off_threads="no"
123 if test "x${_efl_have_posix_threads}" = "xyes" && test "x${_efl_enable_on_off_threads}" = "xyes"; then
124 efl_have_on_off_threads="yes"
125 AC_DEFINE([EFL_ON_OFF_THREADS], [1], [make it possible to disable all locks])
127 AC_MSG_CHECKING([whether to turn on/off threads lock on demand])
128 AC_MSG_RESULT([${efl_have_on_off_threads}])
130 dnl Check debug threads
132 _efl_enable_debug_threads="no"
133 AC_ARG_ENABLE([debug-threads],
134 [AC_HELP_STRING([--enable-debug-threads], [disable assert when you forgot to call eina_threads_init])],
135 [_efl_enable_debug_threads="${enableval}"])
137 efl_have_debug_threads="no"
138 if test "x${_efl_have_posix_threads}" = "xyes" && test "x${_efl_enable_debug_threads}" = "xyes"; then
139 efl_have_debug_threads="yes"
140 AC_DEFINE([EFL_DEBUG_THREADS], [1], [Assert when forgot to call eina_threads_init])
143 AS_IF([test "x$_efl_have_posix_threads" = "xyes" || test "x$_efl_have_win32_threads" = "xyes"], [$1], [$2])