]>
Commit | Line | Data |
---|---|---|
1 | // 2004-08-25 Benjamin Kosnik <bkoz@redhat.com> | |
2 | // | |
3 | // Copyright (C) 2004-2024 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 3, 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 COPYING3. If not see | |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
20 | #include <testsuite_hooks.h> | |
21 | #include <memory> | |
22 | #include <ext/mt_allocator.h> | |
23 | ||
24 | // Tune characteristics, two of same type | |
25 | template<typename _Tp> | |
26 | struct test_policy | |
27 | { static bool per_type() { return true; } }; | |
28 | ||
29 | using __gnu_cxx::__pool; | |
30 | using __gnu_cxx::__common_pool_policy; | |
31 | ||
32 | template<> | |
33 | struct test_policy<__common_pool_policy<__pool, true> > | |
34 | { static bool per_type() { return false; } }; | |
35 | ||
36 | template<> | |
37 | struct test_policy<__common_pool_policy<__pool, false> > | |
38 | { static bool per_type() { return false; } }; | |
39 | ||
40 | struct pod2 | |
41 | { | |
42 | int i; | |
43 | int j; | |
44 | int k; | |
45 | }; | |
46 | ||
47 | // Tune characteristics, two of different instantiations | |
48 | template<typename _Tp, typename _Cp> | |
49 | void test04() | |
50 | { | |
51 | typedef __gnu_cxx::__pool_base::_Tune tune_type; | |
52 | typedef _Tp value_type; | |
53 | typedef _Cp policy_type; | |
54 | typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type; | |
55 | ||
56 | allocator_type a; | |
57 | tune_type t_default = a._M_get_options(); | |
58 | tune_type t_opt(32, 5120, 32, 5120, 20, 10, false); | |
59 | tune_type t_small(16, 1024, 32, 2048, 1, 10, false); | |
60 | ||
61 | // First instance of local type assured. | |
62 | tune_type t1 = t_default; | |
63 | if (test_policy<policy_type>::per_type()) | |
64 | { | |
65 | a._M_set_options(t_opt); | |
66 | t1 = a._M_get_options(); | |
67 | VERIFY( t1._M_align != t_default._M_align ); | |
68 | } | |
69 | ||
70 | // Lock tune settings. | |
71 | typename allocator_type::pointer p1 = a.allocate(128); | |
72 | ||
73 | typedef pod2 value2_type; | |
74 | typedef typename allocator_type::template rebind<value2_type>::other rebind_type; | |
75 | ||
76 | rebind_type a2; | |
77 | tune_type t2 = a2._M_get_options(); | |
78 | ||
79 | // Both policy_type and rebind_type::policy_type have same characteristics. | |
80 | if (test_policy<policy_type>::per_type()) | |
81 | { | |
82 | a2._M_set_options(t_opt); | |
83 | tune_type t = a2._M_get_options(); | |
84 | VERIFY( t2._M_align != t._M_align ); | |
85 | t2 = t; | |
86 | } | |
87 | ||
88 | typename rebind_type::pointer p2 = a2.allocate(5128); | |
89 | ||
90 | a2._M_set_options(t_small); | |
91 | tune_type t4 = a2._M_get_options(); | |
92 | VERIFY( t4._M_chunk_size != t_small._M_chunk_size ); | |
93 | VERIFY( t4._M_chunk_size == t2._M_chunk_size ); | |
94 | ||
95 | a.deallocate(p1, 128); | |
96 | a2.deallocate(p2, 5128); | |
97 | } | |
98 | ||
99 | int main() | |
100 | { | |
101 | #ifdef __GTHREADS | |
102 | test04<float, __gnu_cxx::__common_pool_policy<__pool, true> >(); | |
103 | test04<double, __gnu_cxx::__per_type_pool_policy<double, __pool, true> >(); | |
104 | #endif | |
105 | test04<float, __gnu_cxx::__common_pool_policy<__pool, false> >(); | |
106 | test04<double, __gnu_cxx::__per_type_pool_policy<double, __pool, false> >(); | |
107 | ||
108 | return 0; | |
109 | } |