2 // Utilities for testing threads for the C++ library testsuite.
4 // Copyright (C) 2009-2020 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This 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
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #ifndef _GLIBCXX_TESTSUITE_THREAD_H
23 #define _GLIBCXX_TESTSUITE_THREAD_H
27 #include <type_traits>
33 // Assume _Tp::native_handle_type.
34 // Check C++ to native_handle_type characteristics: size and alignment.
35 template<typename _Tp
>
37 compare_type_to_native_type()
39 typedef _Tp test_type
;
41 // Remove possible pointer type.
42 typedef typename
test_type::native_handle_type native_handle
;
43 // For std::thread native_handle_type is the type of its data member,
44 // for other types it's a pointer to the type of the data member.
45 typedef typename
std::conditional
<
46 std::is_same
<test_type
, std::thread
>::value
,
48 typename
std::remove_pointer
<native_handle
>::type
>::type native_type
;
50 int st
= sizeof(test_type
);
51 int snt
= sizeof(native_type
);
52 int at
= __alignof__(test_type
);
53 int ant
= __alignof__(native_type
);
54 if (st
!= snt
|| at
!= ant
)
58 s
<< "size of _Tp: " << st
<< std::endl
;
59 s
<< "alignment of _Tp: " << st
<< std::endl
;
60 s
<< "size of *(_Tp::native_handle_type): " << snt
<< std::endl
;
61 s
<< "alignment of *(_Tp::native_handle_type): " << snt
<< std::endl
;
62 throw std::runtime_error(s
.str());
65 } // namespace __gnu_test
67 #endif // _GLIBCXX_TESTSUITE_THREAD_H