tune-3.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // 2004-08-25 Benjamin Kosnik <bkoz@redhat.com>
  2. //
  3. // Copyright (C) 2004-2022 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 3, 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 COPYING3. If not see
  18. // <http://www.gnu.org/licenses/>.
  19. #include <testsuite_hooks.h>
  20. #include <memory>
  21. #include <ext/mt_allocator.h>
  22. // Tune characteristics, two of same type
  23. template<typename _Tp>
  24. struct test_policy
  25. { static bool per_type() { return true; } };
  26. using __gnu_cxx::__pool;
  27. using __gnu_cxx::__common_pool_policy;
  28. template<>
  29. struct test_policy<__common_pool_policy<__pool, true> >
  30. { static bool per_type() { return false; } };
  31. template<>
  32. struct test_policy<__common_pool_policy<__pool, false> >
  33. { static bool per_type() { return false; } };
  34. // Tune characteristics, two of different types
  35. template<typename _Tp, typename _Cp>
  36. void test03()
  37. {
  38. typedef __gnu_cxx::__pool_base::_Tune tune_type;
  39. typedef _Tp value_type;
  40. typedef _Cp policy_type;
  41. typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
  42. allocator_type a;
  43. tune_type t_default = a._M_get_options();
  44. tune_type t_opt(32, 5120, 32, 5120, 20, 10, false);
  45. tune_type t_small(16, 1024, 32, 2048, 1, 10, false);
  46. // First instances assured.
  47. tune_type t1 = t_default;
  48. if (test_policy<policy_type>::per_type())
  49. {
  50. a._M_set_options(t_opt);
  51. t1 = a._M_get_options();
  52. VERIFY( t1._M_align != t_default._M_align );
  53. }
  54. // Lock tune settings.
  55. typename allocator_type::pointer p1 = a.allocate(128);
  56. allocator_type a2;
  57. tune_type t2 = a2._M_get_options();
  58. VERIFY( t2._M_chunk_size == t1._M_chunk_size );
  59. typename allocator_type::pointer p2 = a2.allocate(5128);
  60. a2._M_set_options(t_small);
  61. tune_type t3 = a2._M_get_options();
  62. VERIFY( t3._M_chunk_size != t_small._M_chunk_size );
  63. VERIFY( t3._M_chunk_size == t2._M_chunk_size );
  64. a.deallocate(p1, 128);
  65. a2.deallocate(p2, 5128);
  66. }
  67. int main()
  68. {
  69. #ifdef __GTHREADS
  70. test03<int, __gnu_cxx::__per_type_pool_policy<int, __pool, true> >();
  71. test03<int, __gnu_cxx::__common_pool_policy<__pool, true> >();
  72. #endif
  73. test03<int, __gnu_cxx::__per_type_pool_policy<int, __pool, false> >();
  74. test03<int, __gnu_cxx::__common_pool_policy<__pool, false> >();
  75. return 0;
  76. }