1 | ## $Id: yat_thread.m4 3960 2020-08-01 04:17:31Z peter $ |
---|
2 | # |
---|
3 | # Copyright (C) 2020 Peter Johansson |
---|
4 | # |
---|
5 | # This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
6 | # |
---|
7 | # The yat library is free software; you can redistribute it and/or |
---|
8 | # modify it under the terms of the GNU General Public License as |
---|
9 | # published by the Free Software Foundation; either version 3 of the |
---|
10 | # License, or (at your option) any later version. |
---|
11 | # |
---|
12 | # The yat library is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | # General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | # |
---|
20 | |
---|
21 | # |
---|
22 | # serial 1 (yat 0.18) |
---|
23 | # |
---|
24 | |
---|
25 | |
---|
26 | # YAT_THREAD |
---|
27 | # ==================== |
---|
28 | AC_DEFUN([YAT_THREAD], |
---|
29 | [ |
---|
30 | YAT_THREAD_COMPILE_IFELSE_([ |
---|
31 | yat_thread_save_CPPFLAGS="$CPPFLAGS" |
---|
32 | |
---|
33 | YAT_CHECK_LIBS([for linker flag needed for thread], |
---|
34 | [yat_cv_thread_libs], [pthread], |
---|
35 | [YAT_THREAD_PROGRAM_], |
---|
36 | [CPPFLAGS="$yat_thread_save_CPPFLAGS" |
---|
37 | $1], |
---|
38 | [CPPFLAGS="$yat_thread_save_CPPFLAGS" |
---|
39 | $2]) |
---|
40 | ], [ |
---|
41 | $2 |
---|
42 | ]) |
---|
43 | ]) #YAT_THREAD |
---|
44 | |
---|
45 | |
---|
46 | # Internal macro looking for compiler flags needed for thread support |
---|
47 | AC_DEFUN([YAT_THREAD_COMPILE_IFELSE_], |
---|
48 | [ |
---|
49 | AS_VAR_PUSHDEF([my_CACHE], [yat_cv_thread_cppflags])dnl |
---|
50 | AC_CACHE_CHECK([for compiler flag needed for thread], [my_CACHE], |
---|
51 | [yat_thread_compile_result=unsupported |
---|
52 | yat_thread_compile_CPPFLAGS="$CPPFLAGS" |
---|
53 | for yat_opt in '' '-pthread' '-pthreads' '-mthreads'; do |
---|
54 | AS_VAR_IF([yat_thread_compile_result], [unsupported], [ |
---|
55 | CPPFLAGS="$yat_thread_compile_CPPFLAGS $yat_opt" |
---|
56 | AC_COMPILE_IFELSE([YAT_THREAD_PROGRAM_], |
---|
57 | [yat_thread_compile_result="$yat_opt"]) |
---|
58 | ]) |
---|
59 | done |
---|
60 | |
---|
61 | # restore flags |
---|
62 | CPPFLAGS="$yat_thread_compile_CPPFLAGS" |
---|
63 | |
---|
64 | # translate test result to someting suitable to display |
---|
65 | AS_CASE([x"$yat_thread_compile_result"], |
---|
66 | [x""], [my_CACHE=none], |
---|
67 | [my_CACHE="$yat_thread_compile_result"]) |
---|
68 | ]) |
---|
69 | |
---|
70 | AS_CASE([$my_CACHE], |
---|
71 | ["none"], [$1], |
---|
72 | [unsupported], [$2], |
---|
73 | [YAT_THREAD_CPPFLAGS="$my_CACHE" |
---|
74 | $1]) |
---|
75 | AS_VAR_POPDEF([my_CACHE]) |
---|
76 | ]) |
---|
77 | |
---|
78 | |
---|
79 | # private macro defining the code used in tests for std::thread |
---|
80 | AC_DEFUN([YAT_THREAD_PROGRAM_], |
---|
81 | [ |
---|
82 | AC_LANG_PROGRAM([[ |
---|
83 | @%:@include <thread> |
---|
84 | void foo(void) {} |
---|
85 | ]], [[ |
---|
86 | std::thread t(foo); |
---|
87 | t.join(); |
---|
88 | ]]) |
---|
89 | ]) |
---|
90 | } |
---|