[6916] Fixed typos in spell checking code.
[getmangos.git] / dep / ACE_wrappers / m4 / threads.m4
blobf8b2058d9241e125665bf48fdf26475c9e252d42
1 dnl -------------------------------------------------------------------------
2 dnl       $Id: threads.m4 80826 2008-03-04 14:51:23Z wotte $
3 dnl
4 dnl       threads.m4
5 dnl
6 dnl       ACE M4 include file which contains ACE specific M4 macros
7 dnl       for configuring thread support.  This file is to be used
8 dnl       with the configure script.
9 dnl
10 dnl -------------------------------------------------------------------------
12 dnl  Copyright (C) 1998, 1999, 2002  Ossama Othman
13 dnl
14 dnl  All Rights Reserved
15 dnl
16 dnl This library is free software; you can redistribute it and/or
17 dnl modify it under the current ACE distribution terms.
18 dnl
19 dnl This library is distributed in the hope that it will be useful,
20 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
21 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 dnl Make sure thread library exists
24 dnl We need to be careful when tests for other thread libraries are
25 dnl added that we don't screw up handling of "ace_user_enable_threads"
26 dnl Tests should probably be more platform specific later on.
28 dnl Check for thread related libraries and compiler flags
29 dnl Usage: ACE_CHECK_THREADS
30 AC_DEFUN([ACE_CHECK_THREADS],
32 dnl  AC_REQUIRE([AC_PROG_CXX])
33 dnl  AC_REQUIRE([AC_PROG_CXXCPP])
34 dnl  AC_LANG([C++])
35 dnl  AC_REQUIRE([AC_LANG])
37  dnl Check if compiler accepts specific flag to enable threads
38  ACE_CACHE_CHECK([if compiler may need a command line thread flag],
39    [ace_cv_feature_may_need_thread_flag],
40    [
41     ace_save_CXXFLAGS="$CXXFLAGS"
43     ACE_CHECK_THREAD_FLAGS(
44       [
45        ace_cv_feature_may_need_thread_flag=no
46       ],
47       [
48        ace_cv_feature_may_need_thread_flag=yes
49       ])
50     dnl Reset the flags to a consistent state.
51     dnl This prevents duplicate flags from being added to
52     dnl the C/CXXFLAGS variable.
53     CXXFLAGS="$ace_save_CXXFLAGS"
54    ],
55    [
56     dnl The compiler/platform has no thread support linked in by default
57     dnl so search for a usable compiler flag to enable thread support.
58     dnl If no thread flag is found then the remaining tests should still
59     dnl figure out how to enable thread support via library checks.
60     ACE_SEARCH_THREAD_FLAGS(
61       [mt pthread pthreads mthreads threads Kthread kthread -thread_safe],,)
62       dnl NOTE: "-thread_safe" is correct, not "thread_safe."
63       dnl       KAI C++ uses the flag "--thread_safe" which is why
64       dnl       "-thread_safe" is passed as the flag to test.
65    ],
66    [
67     dnl Do nothing
68    ])
70  dnl Check for UNIX International Threads (ACE calls this STHREADS)
71  dnl This used to check for thr_create(), but AIX has a semi-functional
72  dnl UI Threads capability that includes thr_create(). We don't want to
73  dnl find such a half-hearted UI Threads, so this was changed to look for
74  dnl a UI Threads function that AIX doesn't offer.
75  AS_IF([test "$ace_user_enable_uithreads" = yes],
76    [ AC_MSG_CHECKING([for UNIX International threads capability])
77      AC_SEARCH_LIBS([mutex_lock], [thread],
78      [
79        ace_has_sthreads=yes
80        AC_DEFINE([ACE_HAS_STHREADS], 1, 
81                  [Define to 1 if platform has UNIX International Threads])
82      ],
83      [
84        ace_has_sthreads=no
85      ])
86      dnl Sometimes thr_create is actually found with explicitly linking against
87      dnl -lthread, so try a more "exotic" function.
88      AC_SEARCH_LIBS([rwlock_destroy], [thread],[],[])
89      AC_MSG_RESULT([$ace_has_sthreads])
90    ],[])
92  dnl Check if any thread related preprocessor flags are needed.
93  ACE_CHECK_THREAD_CPPFLAGS
95  dnl Check for POSIX threads
96  ace_has_pthreads=no
97  AS_IF([test "$ace_user_enable_pthreads" = yes],
98    [ AC_MSG_CHECKING([for POSIX threads library])
99      ACE_CHECK_POSIX_THREADS(
100        [
101          ace_has_pthreads=yes
102          AC_DEFINE([ACE_HAS_PTHREADS], 1,
103                    [Define to 1 if platform has POSIX threads])
104          AC_MSG_RESULT([none required])
105        ],
106        [])
108      AS_IF([test "$ace_has_pthreads" != yes],
109        [
110          ace_posix_threads_search_LIBS="$LIBS"
111          for ace_p in pthread pthreads c_r gthreads; do
112            LIBS="-l$ace_p $ace_posix_threads_search_LIBS"
113            ACE_CHECK_POSIX_THREADS(
114              [
115                ace_has_pthreads=yes
116                AC_DEFINE([ACE_HAS_PTHREADS])
117                AC_MSG_RESULT([-l$ace_p])
118                break
119              ],
120              [])
121          done
123          AS_IF([test "$ace_has_pthreads" != yes],
124            [
125              AC_MSG_RESULT([no])
126              LIBS="$ace_posix_threads_search_LIBS"
127            ],[])
128         ],
129         [])
130    ],
131    [
132      AC_MSG_NOTICE([Pthreads disabled by user; not checking for it])
133    ])
135  dnl If we don't have any thread library, then disable threading altogether!
136  AS_IF([test "$ace_has_pthreads" != yes && test "$ace_has_sthreads" != yes],
137   [
138    ace_user_enable_threads=no
139   ])
142 dnl This macro will check that the current compiler flags do something
143 dnl useful in terms of thread libraries and/or functions.
144 dnl Usage: ACE_CHECK_THREAD_FLAGS(ACTION-IF-USABLE [, ACTION-IF-NOT-USABLE]])
145 AC_DEFUN([ACE_CHECK_THREAD_FLAGS],
147  ACE_CONVERT_WARNINGS_TO_ERRORS([
148  dnl Check for UI thread support first.
150  dnl Because some platforms are brain damaged enough to provide
151  dnl useless thread function stubs, link tests may succeed despite the
152  dnl fact the stubs are no-ops.  This forces us to use a run-time test
153  dnl to get around this nuisance by checking the return value of
154  dnl thr_create().  The cross-compiled case will use a link-time
155  dnl test, instead.
156  dnl Furthermore, we need the implementation to be a real one, not
157  dnl a half-hearted attempt such as that provided on AIX 5. So, we
158  dnl make sure it can at least work with a mutex.
160  AC_RUN_IFELSE([AC_LANG_SOURCE([[
161 #include <thread.h>
162 #if ((THR_BOUND & THR_SUSPEND & THR_DETACHED) != 0)
163 #  error This is a silly UI Threads implementation.
164 #endif
166 extern "C" void *
167 ace_start_func (void *)
169  mutex_t m;
170  mutex_init (&m, USYNC_THREAD, NULL);
171  mutex_lock (&m);
172  mutex_unlock (&m);
173  mutex_destroy (&m);
174  return 0;
178 main ()
180  thread_t tid = 0;
182  return thr_create (0, 0, ace_start_func, 0, 0, &tid);
184    ]])],
185    [$1],
186    [
187  dnl Now check for POSIX thread support.
188     ACE_CHECK_POSIX_THREADS([$1],[$2])
190    ],
191    [
192     dnl UI threads cross-compiled case
194     AC_LINK_IFELSE([AC_LANG_PROGRAM([[
195 #include <thread.h>
197 extern "C" void *
198 ace_start_func (void *)
200  return 0;
202       ]],
203       [[
204  thread_t tid = 0;
206  (void) thr_create (&tid, 0, ace_start_func, 0);
207       ]])],
208       [$1],
209       [$2])
210     ])
211  ])
214 dnl Check what compiler thread flag may be used, if any, from the given list.
215 dnl The flag list is separated by white space.
216 dnl Usage: ACE_SEARCH_THREAD_FLAGS(THREAD-FLAG-LIST,
217 dnl                                [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
218 AC_DEFUN([ACE_SEARCH_THREAD_FLAGS],
220  AC_LANG([C++])
221  AC_REQUIRE([AC_LANG])
223  ACE_CACHE_CHECK([for compiler thread flag],
224    [ace_cv_thread_flag_search],
225    [
226     ace_save_CXXFLAGS="$CXXFLAGS"
228     for i in $1; do
229       CXXFLAGS="$CXXFLAGS -$i"
231       ACE_CHECK_THREAD_FLAGS(
232         [
233          ace_cv_thread_flag_search="-$i"
235          dnl A usable flag was found so break out of the loop.
236          break;
237         ],
238         [
239          ace_cv_thread_flag_search=no
240         ])
242       dnl Reset the flags for the next flag check.
243       CXXFLAGS="$ace_save_CXXFLAGS"
244     done
246     dnl Reset the flags to a consistent state.
247     dnl This prevents duplicate flags from being added to
248     dnl the CCXXFLAGS variable.
249     CXXFLAGS="$ace_save_CXXFLAGS"
250    ],
251    [
252     dnl Add the found/cached thread flag to the C/CXXFLAGS variables
253     CXXFLAGS="$CXXFLAGS $ace_cv_thread_flag_search"
255     $2
256    ],
257    [
258     $3
259    ])
263 dnl Check if the compiler defines thread related preprocessor flags.
264 dnl If not, then provide them.
265 dnl Usage: ACE_CHECK_THREAD_CPPFLAGS
266 AC_DEFUN([ACE_CHECK_THREAD_CPPFLAGS],
268  dnl A compile-time test is used instead of a preprocesse-time test
269  dnl because compiler thread flags defined in CFLAGS or CXXFLAGS
270  dnl should be used for this test.
271  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
272 #if !defined (_REENTRANT) && !defined (_THREAD_SAFE)
273 #error Neither _REENTRANT nor _THREAD_SAFE were defined.
274 THROW ME AN ERROR!
275 #endif
276    ]], [[
277     int a = 0; a++;
278    ]])],[
279     ACE_THR_CPPFLAGS=
280    ],[
281     ACE_THR_CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE"
282    ])
285 dnl Check for POSIX threads support.
286 dnl Usage: ACE_CHECK_POSIX_THREADS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
287 AC_DEFUN([ACE_CHECK_POSIX_THREADS],
289  dnl Because some platforms are brain damaged enough to provide
290  dnl useless thread function stubs, link tests may succeed despite the
291  dnl fact the stubs are no-ops.  This forces us to use a run-time test
292  dnl to get around this nuisance by checking the return value of
293  dnl pthread_create().  The cross-compiled case will use a link-time
294  dnl test, instead.
295  AC_RUN_IFELSE([AC_LANG_SOURCE([[
296 #include <pthread.h>
298 extern "C" void *
299 ace_start_func (void *)
301  return 0;
305 main ()
307  pthread_t tid = 0;
309  return pthread_create (&tid, 0, ace_start_func, 0);
311       ]])],
312       [$1],
313       [$2],
314       [
315        dnl POSIX threads check -- cross-compiled case
317        AC_LINK_IFELSE([AC_LANG_PROGRAM([[
318 #include <pthread.h>
320 extern "C" void *
321 ace_start_func (void *)
323  return 0;
325          ]],
326          [[
327  pthread_t tid = 0;
329  (void) pthread_create (&tid, 0, ace_start_func, 0);
330          ]])],
331          [$1],
332          [$2])
333       ])