* Merge with edge-vector-mergepoint-20040918.
[official-gcc.git] / libstdc++-v3 / testsuite / ext / mt_allocator / tune-4.cc
blobda85295a5defdf42e6daef1c4deaadf992d0be53
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.
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.
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
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 #include <testsuite_hooks.h>
22 #include <memory>
23 #include <ext/mt_allocator.h>
25 // Tune characteristics, two of same type
26 template<typename _Tp>
27 struct test_policy
28 { static bool per_type() { return true; } };
30 template<bool _Thread>
31 struct test_policy<__gnu_cxx::__common_pool_policy<_Thread> >
33 typedef __gnu_cxx::__common_pool_policy<_Thread> pool_type;
34 static bool per_type() { return false; }
37 struct pod2
39 int i;
40 int j;
43 // Tune characteristics, two of different instantiations
44 template<typename _Tp, typename _Cp>
45 void test04()
47 bool test __attribute__((unused)) = true;
49 typedef __gnu_cxx::__pool_base::_Tune tune_type;
50 typedef _Tp value_type;
51 typedef _Cp policy_type;
53 typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
54 tune_type t_default;
55 tune_type t_opt(16, 5120, 32, 5120, 20, 10, false);
56 tune_type t_single(16, 5120, 32, 5120, 1, 10, false);
58 allocator_type a;
59 tune_type t1 = a._M_get_options();
60 tune_type t2;
61 if (test_policy<policy_type>::per_type())
63 VERIFY( t1._M_align == t_default._M_align );
64 a._M_set_options(t_opt);
65 t2 = a._M_get_options();
66 VERIFY( t1._M_align != t2._M_align );
68 else
69 t2 = t1;
71 // Lock tune settings.
72 typename allocator_type::pointer p1 = a.allocate(128);
74 // First instance of local type assured.
75 typedef pod2 value2_type;
76 typedef typename allocator_type::template rebind<value2_type>::other rebind_type;
78 rebind_type a2;
79 tune_type t3 = a2._M_get_options();
80 tune_type t4;
82 // Both policy_type and rebind_type::policy_type have same characteristics.
83 if (test_policy<policy_type>::per_type())
85 VERIFY( t3._M_align == t_default._M_align );
86 a2._M_set_options(t_opt);
87 t4 = a2._M_get_options();
88 VERIFY( t3._M_align != t4._M_align );
89 t3 = t4;
91 else
92 VERIFY( t3._M_max_threads == t2._M_max_threads );
94 typename rebind_type::pointer p2 = a2.allocate(5128);
96 a2._M_set_options(t_single);
97 t4 = a2._M_get_options();
98 VERIFY( t4._M_max_threads != t_single._M_max_threads );
99 VERIFY( t4._M_max_threads == t3._M_max_threads );
101 a.deallocate(p1, 128);
102 a2.deallocate(p2, 5128);
105 int main()
107 #ifdef __GTHREADS
108 test04<float, __gnu_cxx::__common_pool_policy<true> >();
109 test04<double, __gnu_cxx::__per_type_pool_policy<double, true> >();
110 #endif
111 test04<float, __gnu_cxx::__common_pool_policy<false> >();
112 test04<double, __gnu_cxx::__per_type_pool_policy<double, false> >();
114 return 0;