OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [ext/] [mt_allocator/] [tune-4.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.