Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / testsuite / ext / mt_allocator / tune-3.cc
blob1c749129432c8ea2b6fbd28a6fc545914e31da05
1 // 2004-08-25 Benjamin Kosnik <bkoz@redhat.com>
2 //
3 // Copyright (C) 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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 using __gnu_cxx::__pool;
31 using __gnu_cxx::__common_pool_policy;
33 template<>
34 struct test_policy<__common_pool_policy<__pool, true> >
35 { static bool per_type() { return false; } };
37 template<>
38 struct test_policy<__common_pool_policy<__pool, false> >
39 { static bool per_type() { return false; } };
41 // Tune characteristics, two of different types
42 template<typename _Tp, typename _Cp>
43 void test03()
45 bool test __attribute__((unused)) = true;
47 typedef __gnu_cxx::__pool_base::_Tune tune_type;
48 typedef _Tp value_type;
49 typedef _Cp policy_type;
50 typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
52 allocator_type a;
53 tune_type t_default = a._M_get_options();
54 tune_type t_opt(32, 5120, 32, 5120, 20, 10, false);
55 tune_type t_small(16, 1024, 32, 2048, 1, 10, false);
57 // First instances assured.
58 tune_type t1 = t_default;
59 if (test_policy<policy_type>::per_type())
61 a._M_set_options(t_opt);
62 t1 = a._M_get_options();
63 VERIFY( t1._M_align != t_default._M_align );
66 // Lock tune settings.
67 typename allocator_type::pointer p1 = a.allocate(128);
69 allocator_type a2;
70 tune_type t2 = a2._M_get_options();
71 VERIFY( t2._M_chunk_size == t1._M_chunk_size );
73 typename allocator_type::pointer p2 = a2.allocate(5128);
75 a2._M_set_options(t_small);
76 tune_type t3 = a2._M_get_options();
77 VERIFY( t3._M_chunk_size != t_small._M_chunk_size );
78 VERIFY( t3._M_chunk_size == t2._M_chunk_size );
80 a.deallocate(p1, 128);
81 a2.deallocate(p2, 5128);
84 int main()
86 #ifdef __GTHREADS
87 test03<int, __gnu_cxx::__per_type_pool_policy<int, __pool, true> >();
88 test03<int, __gnu_cxx::__common_pool_policy<__pool, true> >();
89 #endif
91 test03<int, __gnu_cxx::__per_type_pool_policy<int, __pool, false> >();
92 test03<int, __gnu_cxx::__common_pool_policy<__pool, false> >();
94 return 0;