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