]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/ext/mt_allocator/tune-4.cc
re PR libmudflap/23084 (mudflap crash upon accept() with argement 2 and 3 as NULL)
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / mt_allocator / tune-4.cc
CommitLineData
8bfd0a46
BK
1// 2004-08-25 Benjamin Kosnik <bkoz@redhat.com>
2//
3// Copyright (C) 2004 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
9// any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING. If not, write to the Free
83f51799 18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
8bfd0a46
BK
19// USA.
20
3641bd55 21#include <testsuite_hooks.h>
8bfd0a46
BK
22#include <memory>
23#include <ext/mt_allocator.h>
24
8bfd0a46
BK
25// Tune characteristics, two of same type
26template<typename _Tp>
27struct test_policy
28{ static bool per_type() { return true; } };
29
6571df13
BK
30using __gnu_cxx::__pool;
31using __gnu_cxx::__common_pool_policy;
32
33template<>
34struct test_policy<__common_pool_policy<__pool, true> >
35{ static bool per_type() { return false; } };
36
37template<>
38struct test_policy<__common_pool_policy<__pool, false> >
39{ static bool per_type() { return false; } };
8bfd0a46
BK
40
41struct pod2
42{
43 int i;
44 int j;
61b26514 45 int k;
8bfd0a46
BK
46};
47
48// Tune characteristics, two of different instantiations
49template<typename _Tp, typename _Cp>
50void test04()
51{
3641bd55
PC
52 bool test __attribute__((unused)) = true;
53
8bfd0a46
BK
54 typedef __gnu_cxx::__pool_base::_Tune tune_type;
55 typedef _Tp value_type;
56 typedef _Cp policy_type;
57
58 typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
8bfd0a46
BK
59 tune_type t_opt(16, 5120, 32, 5120, 20, 10, false);
60 tune_type t_single(16, 5120, 32, 5120, 1, 10, false);
61
62 allocator_type a;
61b26514
BK
63 tune_type t_default = a._M_get_options();
64 tune_type t1 = t_default;
8bfd0a46
BK
65 tune_type t2;
66 if (test_policy<policy_type>::per_type())
67 {
8bfd0a46
BK
68 a._M_set_options(t_opt);
69 t2 = a._M_get_options();
3641bd55 70 VERIFY( t1._M_align != t2._M_align );
8bfd0a46
BK
71 }
72 else
73 t2 = t1;
74
75 // Lock tune settings.
76 typename allocator_type::pointer p1 = a.allocate(128);
77
78 // First instance of local type assured.
79 typedef pod2 value2_type;
80 typedef typename allocator_type::template rebind<value2_type>::other rebind_type;
81
82 rebind_type a2;
83 tune_type t3 = a2._M_get_options();
84 tune_type t4;
85
86 // Both policy_type and rebind_type::policy_type have same characteristics.
87 if (test_policy<policy_type>::per_type())
88 {
8bfd0a46 89 a2._M_set_options(t_opt);
3641bd55
PC
90 t4 = a2._M_get_options();
91 VERIFY( t3._M_align != t4._M_align );
8bfd0a46
BK
92 t3 = t4;
93 }
94 else
3641bd55 95 VERIFY( t3._M_max_threads == t2._M_max_threads );
8bfd0a46
BK
96
97 typename rebind_type::pointer p2 = a2.allocate(5128);
98
99 a2._M_set_options(t_single);
3641bd55
PC
100 t4 = a2._M_get_options();
101 VERIFY( t4._M_max_threads != t_single._M_max_threads );
102 VERIFY( t4._M_max_threads == t3._M_max_threads );
8bfd0a46
BK
103
104 a.deallocate(p1, 128);
105 a2.deallocate(p2, 5128);
106}
107
108int main()
109{
110#ifdef __GTHREADS
6571df13
BK
111 test04<float, __gnu_cxx::__common_pool_policy<__pool, true> >();
112 test04<double, __gnu_cxx::__per_type_pool_policy<double, __pool, true> >();
8bfd0a46 113#endif
6571df13
BK
114 test04<float, __gnu_cxx::__common_pool_policy<__pool, false> >();
115 test04<double, __gnu_cxx::__per_type_pool_policy<double, __pool, false> >();
8bfd0a46
BK
116
117 return 0;
118}