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="-mt"
33 _efl_threads_libs="-mt"
36 _efl_enable_posix_threads="yes"
37 _efl_threads_cflags="-pthread"
38 _efl_threads_libs="-pthread"
42 dnl check if the compiler supports POSIX threads
45 if test "x${_efl_enable_posix_threads}" = "xyes" ; then
48 CFLAGS="${CFLAGS} ${_efl_threads_cflags}"
50 LIBS="${LIBS} ${_efl_threads_libs}"
60 _efl_have_posix_threads="yes"
61 AC_DEFINE([EFL_HAVE_POSIX_THREADS], [1], [Define to mention that POSIX threads are supported])
62 AC_DEFINE([EFL_HAVE_THREADS], [1], [Define to mention that POSIX or Win32 threads are supported])
63 EFL_PTHREAD_CFLAGS=${_efl_threads_cflags}
64 EFL_PTHREAD_LIBS=${_efl_threads_libs}
66 [_efl_have_posix_threads="no"])
72 AC_MSG_CHECKING([which threads API is used])
73 if test "x${_efl_have_posix_threads}" = "xyes" ; then
74 efl_have_threads="POSIX"
76 if test "x${_efl_have_win32_threads}" = "xyes" ; then
77 efl_have_threads="Windows"
82 AC_MSG_RESULT([${efl_have_threads}])
84 AC_SUBST(EFL_PTHREAD_CFLAGS)
85 AC_SUBST(EFL_PTHREAD_LIBS)
87 dnl check if the compiler supports pthreads spinlock
89 efl_have_posix_threads_spinlock="no"
91 if test "x${_efl_have_posix_threads}" = "xyes" ; then
94 CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}"
96 LIBS="${LIBS} ${EFL_PTHREAD_LIBS}"
102 pthread_spinlock_t lock;
104 res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
106 [efl_have_posix_threads_spinlock="yes"],
107 [efl_have_posix_threads_spinlock="no"])
108 CFLAGS=${SAVE_CFLAGS}
113 AC_MSG_CHECKING([whether to build POSIX threads spinlock code])
114 AC_MSG_RESULT([${efl_have_posix_threads_spinlock}])
116 if test "x${efl_have_posix_threads_spinlock}" = "xyes" ; then
117 AC_DEFINE([EFL_HAVE_POSIX_THREADS_SPINLOCK], [1], [Define to mention that POSIX threads spinlocks are supported])
120 dnl Check ON-OFF threads
122 _efl_enable_on_off_threads="no"
123 AC_ARG_ENABLE([on-off-threads],
124 [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])],
125 [_efl_enable_on_off_threads="${enableval}"])
127 efl_have_on_off_threads="no"
128 if test "x${_efl_have_posix_threads}" = "xyes" && test "x${_efl_enable_on_off_threads}" = "xyes"; then
129 efl_have_on_off_threads="yes"
130 AC_DEFINE([EFL_ON_OFF_THREADS], [1], [make it possible to disable all locks])
132 AC_MSG_CHECKING([whether to turn on/off threads lock on demand])
133 AC_MSG_RESULT([${efl_have_on_off_threads}])
135 dnl Check debug threads
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 efl_have_debug_threads="no"
143 if test "x${_efl_have_posix_threads}" = "xyes" && test "x${_efl_enable_debug_threads}" = "xyes"; then
144 efl_have_debug_threads="yes"
145 AC_DEFINE([EFL_DEBUG_THREADS], [1], [Assert when forgot to call eina_threads_init])
148 AS_IF([test "x$_efl_have_posix_threads" = "xyes" || test "x$_efl_have_win32_threads" = "xyes"], [$1], [$2])