summaryrefslogtreecommitdiff
path: root/m4/efl_threads.m4
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-09-16 10:57:48 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-09-16 10:57:48 +0000
commit785f2a6b3a70454ecfe94addc6480ebf20c44c13 (patch)
tree17a195d2c1f022cd480fd0e0b95be5035ad915e2 /m4/efl_threads.m4
parentdfc0331373c3f98df7cb996abc588c7dcf44af0a (diff)
merge : add eina
currently, examples, tests and benchmark are not set. That's the next things i'll do SVN revision: 76710
Diffstat (limited to 'm4/efl_threads.m4')
-rw-r--r--m4/efl_threads.m4149
1 files changed, 149 insertions, 0 deletions
diff --git a/m4/efl_threads.m4 b/m4/efl_threads.m4
new file mode 100644
index 0000000..ae29606
--- /dev/null
+++ b/m4/efl_threads.m4
@@ -0,0 +1,149 @@
1dnl Copyright (C) 2010 Vincent Torri <vtorri at univ-evry dot fr>
2dnl rwlock code added by Mike Blumenkrantz <mike at zentific dot com>
3dnl This code is public domain and can be freely used or copied.
4
5dnl Macro that check if POSIX or Win32 threads library is available or not.
6
7dnl Usage: EFL_CHECK_THREADS(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
8dnl Call AC_SUBST(EFL_PTHREAD_CFLAGS)
9dnl Call AC_SUBST(EFL_PTHREAD_LIBS)
10dnl Defines EFL_HAVE_POSIX_THREADS or EFL_HAVE_WIN32_THREADS, and EFL_HAVE_THREADS
11
12AC_DEFUN([EFL_CHECK_THREADS],
13[
14
15dnl Generic thread detection
16
17EFL_PTHREAD_CFLAGS=""
18EFL_PTHREAD_LIBS=""
19
20_efl_enable_posix_threads="no"
21_efl_have_posix_threads="no"
22_efl_have_win32_threads="no"
23
24case "$host_os" in
25 mingw*)
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])
29 ;;
30 solaris*)
31 _efl_enable_posix_threads="yes"
32 _efl_threads_cflags="-mt"
33 _efl_threads_libs="-mt"
34 ;;
35 *)
36 _efl_enable_posix_threads="yes"
37 _efl_threads_cflags="-pthread"
38 _efl_threads_libs="-pthread"
39 ;;
40esac
41
42dnl check if the compiler supports POSIX threads
43
44
45if test "x${_efl_enable_posix_threads}" = "xyes" ; then
46
47 SAVE_CFLAGS=${CFLAGS}
48 CFLAGS="${CFLAGS} ${_efl_threads_cflags}"
49 SAVE_LIBS=${LIBS}
50 LIBS="${LIBS} ${_efl_threads_libs}"
51 AC_LINK_IFELSE(
52 [AC_LANG_PROGRAM([[
53#include <pthread.h>
54 ]],
55 [[
56pthread_t id;
57id = pthread_self();
58 ]])],
59 [
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}
65 ],
66 [_efl_have_posix_threads="no"])
67 CFLAGS=${SAVE_CFLAGS}
68 LIBS=${SAVE_LIBS}
69
70fi
71
72AC_MSG_CHECKING([which threads API is used])
73if test "x${_efl_have_posix_threads}" = "xyes" ; then
74 efl_have_threads="POSIX"
75else
76 if test "x${_efl_have_win32_threads}" = "xyes" ; then
77 efl_have_threads="Windows"
78 else
79 efl_have_threads="no"
80 fi
81fi
82AC_MSG_RESULT([${efl_have_threads}])
83
84AC_SUBST(EFL_PTHREAD_CFLAGS)
85AC_SUBST(EFL_PTHREAD_LIBS)
86
87dnl check if the compiler supports pthreads spinlock
88
89efl_have_posix_threads_spinlock="no"
90
91if test "x${_efl_have_posix_threads}" = "xyes" ; then
92
93 SAVE_CFLAGS=${CFLAGS}
94 CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}"
95 SAVE_LIBS=${LIBS}
96 LIBS="${LIBS} ${EFL_PTHREAD_LIBS}"
97 AC_LINK_IFELSE(
98 [AC_LANG_PROGRAM([[
99#include <pthread.h>
100 ]],
101 [[
102pthread_spinlock_t lock;
103int res;
104res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
105 ]])],
106 [efl_have_posix_threads_spinlock="yes"],
107 [efl_have_posix_threads_spinlock="no"])
108 CFLAGS=${SAVE_CFLAGS}
109 LIBS=${SAVE_LIBS}
110
111fi
112
113AC_MSG_CHECKING([whether to build POSIX threads spinlock code])
114AC_MSG_RESULT([${efl_have_posix_threads_spinlock}])
115
116if 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])
118fi
119
120dnl Check ON-OFF threads
121
122_efl_enable_on_off_threads="no"
123AC_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}"])
126
127efl_have_on_off_threads="no"
128if 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])
131fi
132AC_MSG_CHECKING([whether to turn on/off threads lock on demand])
133AC_MSG_RESULT([${efl_have_on_off_threads}])
134
135dnl Check debug threads
136
137_efl_enable_debug_threads="no"
138AC_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}"])
141
142efl_have_debug_threads="no"
143if 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])
146fi
147
148AS_IF([test "x$_efl_have_posix_threads" = "xyes" || test "x$_efl_have_win32_threads" = "xyes"], [$1], [$2])
149])