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