]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/ext/mt_allocator/tune-3.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / mt_allocator / tune-3.cc
CommitLineData
8bfd0a46
BK
1// 2004-08-25 Benjamin Kosnik <bkoz@redhat.com>
2//
7adcbafe 3// Copyright (C) 2004-2022 Free Software Foundation, Inc.
8bfd0a46
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
8bfd0a46
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
8bfd0a46 19
3641bd55 20#include <testsuite_hooks.h>
8bfd0a46
BK
21#include <memory>
22#include <ext/mt_allocator.h>
23
8bfd0a46
BK
24// Tune characteristics, two of same type
25template<typename _Tp>
26struct test_policy
27{ static bool per_type() { return true; } };
28
6571df13
BK
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; } };
8bfd0a46
BK
39
40// Tune characteristics, two of different types
41template<typename _Tp, typename _Cp>
42void test03()
43{
44 typedef __gnu_cxx::__pool_base::_Tune tune_type;
45 typedef _Tp value_type;
46 typedef _Cp policy_type;
47 typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
48
8bfd0a46 49 allocator_type a;
61b26514 50 tune_type t_default = a._M_get_options();
8d4addde
BK
51 tune_type t_opt(32, 5120, 32, 5120, 20, 10, false);
52 tune_type t_small(16, 1024, 32, 2048, 1, 10, false);
53
54 // First instances assured.
61b26514 55 tune_type t1 = t_default;
8bfd0a46
BK
56 if (test_policy<policy_type>::per_type())
57 {
8bfd0a46 58 a._M_set_options(t_opt);
8d4addde
BK
59 t1 = a._M_get_options();
60 VERIFY( t1._M_align != t_default._M_align );
8bfd0a46 61 }
8bfd0a46 62
8bfd0a46
BK
63 // Lock tune settings.
64 typename allocator_type::pointer p1 = a.allocate(128);
65
66 allocator_type a2;
8d4addde
BK
67 tune_type t2 = a2._M_get_options();
68 VERIFY( t2._M_chunk_size == t1._M_chunk_size );
8bfd0a46
BK
69
70 typename allocator_type::pointer p2 = a2.allocate(5128);
71
8d4addde
BK
72 a2._M_set_options(t_small);
73 tune_type t3 = a2._M_get_options();
74 VERIFY( t3._M_chunk_size != t_small._M_chunk_size );
75 VERIFY( t3._M_chunk_size == t2._M_chunk_size );
8bfd0a46
BK
76
77 a.deallocate(p1, 128);
78 a2.deallocate(p2, 5128);
79}
80
81int main()
82{
83#ifdef __GTHREADS
6571df13
BK
84 test03<int, __gnu_cxx::__per_type_pool_policy<int, __pool, true> >();
85 test03<int, __gnu_cxx::__common_pool_policy<__pool, true> >();
8bfd0a46
BK
86#endif
87
6571df13
BK
88 test03<int, __gnu_cxx::__per_type_pool_policy<int, __pool, false> >();
89 test03<int, __gnu_cxx::__common_pool_policy<__pool, false> >();
8bfd0a46
BK
90
91 return 0;
92}