From 8c2773e5e8c3eb06fdc16cd38d873b53ffc82507 Mon Sep 17 00:00:00 2001 From: bkoz Date: Mon, 11 Oct 2004 20:26:53 +0000 Subject: [PATCH] 2004-10-11 Benjamin Kosnik PR libstdc++/16614 continued. * include/ext/mt_allocator.h (__per_type_pool_policy::_S_get_pool): Use saner defaults based on specific type characteristics. (__pool_base): Add constructor that takes a _Tune argument. (__pool): Same. * testsuite/ext/mt_allocator/tune-2.cc: Adjust default. * testsuite/ext/mt_allocator/tune-4.cc: Same. * testsuite/ext/mt_allocator/tune-3.cc: Same. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88902 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 12 ++++++ libstdc++-v3/include/ext/mt_allocator.h | 47 ++++++++++++++++------- libstdc++-v3/testsuite/ext/mt_allocator/tune-2.cc | 5 +-- libstdc++-v3/testsuite/ext/mt_allocator/tune-3.cc | 4 +- libstdc++-v3/testsuite/ext/mt_allocator/tune-4.cc | 7 ++-- 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f2c29aab231..c90171e3d21 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2004-10-11 Benjamin Kosnik + + PR libstdc++/16614 continued. + * include/ext/mt_allocator.h + (__per_type_pool_policy::_S_get_pool): Use saner defaults based on + specific type characteristics. + (__pool_base): Add constructor that takes a _Tune argument. + (__pool): Same. + * testsuite/ext/mt_allocator/tune-2.cc: Adjust default. + * testsuite/ext/mt_allocator/tune-4.cc: Same. + * testsuite/ext/mt_allocator/tune-3.cc: Same. + 2004-10-11 Joachim Kuebart Paolo Carlini diff --git a/libstdc++-v3/include/ext/mt_allocator.h b/libstdc++-v3/include/ext/mt_allocator.h index f377d4071c7..5803f5a835b 100644 --- a/libstdc++-v3/include/ext/mt_allocator.h +++ b/libstdc++-v3/include/ext/mt_allocator.h @@ -172,6 +172,9 @@ namespace __gnu_cxx explicit __pool_base() : _M_options(_Tune()), _M_binmap(NULL), _M_init(false) { } + explicit __pool_base(const _Tune& __tune) + : _M_options(__tune), _M_binmap(NULL), _M_init(false) { } + protected: // Configuration options. _Tune _M_options; @@ -307,6 +310,15 @@ namespace __gnu_cxx _M_once = __tmp; } + explicit __pool(const __pool_base::_Tune& __tune) + : __pool_base(__tune), _M_bin(NULL), _M_bin_size(1), + _M_thread_freelist(NULL) + { + // On some platforms, __gthread_once_t is an aggregate. + __gthread_once_t __tmp = __GTHREAD_ONCE_INIT; + _M_once = __tmp; + } + ~__pool(); private: @@ -372,6 +384,9 @@ namespace __gnu_cxx explicit __pool() : _M_bin(NULL), _M_bin_size(1) { } + explicit __pool(const __pool_base::_Tune& __tune) + : __pool_base(__tune), _M_bin(NULL), _M_bin_size(1) { } + ~__pool(); private: @@ -491,7 +506,10 @@ namespace __gnu_cxx static __pool_type& _S_get_pool() { - static __pool_type _S_pool; + // Sane defaults for the __pool_type. + const static size_t __align = __alignof__(_Tp) >= sizeof(typename __pool_type::_Block_record) ? __alignof__(_Tp) : sizeof(typename __pool_type::_Block_record); + static __pool_base::_Tune _S_tune(__align, sizeof(_Tp) * 128, (sizeof(_Tp) * 2) >= __align ? sizeof(_Tp) * 2 : __align, __pool_type::_Tune::_S_chunk_size, __pool_type::_Tune::_S_max_threads, __pool_type::_Tune::_S_freelist_headroom, getenv("GLIBCXX_FORCE_NEW") ? true : false); + static __pool_type _S_pool(_S_tune); return _S_pool; } @@ -531,7 +549,10 @@ namespace __gnu_cxx static __pool_type& _S_get_pool( ) { - static __pool_type _S_pool; + // Sane defaults for the __pool_type. + const static size_t __align = __alignof__(_Tp) >= sizeof(typename __pool_type::_Block_record) ? __alignof__(_Tp) : sizeof(typename __pool_type::_Block_record); + static __pool_base::_Tune _S_tune(__align, sizeof(_Tp) * 128, (sizeof(_Tp) * 2) >= __align ? sizeof(_Tp) * 2 : __align, __pool_type::_Tune::_S_chunk_size, __pool_type::_Tune::_S_max_threads, __pool_type::_Tune::_S_freelist_headroom, getenv("GLIBCXX_FORCE_NEW") ? true : false); + static __pool_type _S_pool(_S_tune); return _S_pool; } @@ -600,15 +621,15 @@ namespace __gnu_cxx class __mt_alloc : public __mt_alloc_base<_Tp>, _Poolp { public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Tp* pointer; - typedef const _Tp* const_pointer; - typedef _Tp& reference; - typedef const _Tp& const_reference; - typedef _Tp value_type; - typedef _Poolp __policy_type; - typedef typename _Poolp::__pool_type __pool_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + typedef _Poolp __policy_type; + typedef typename _Poolp::__pool_type __pool_type; template struct rebind @@ -657,8 +678,8 @@ namespace __gnu_cxx { this->_S_initialize_once(); - // Requests larger than _M_max_bytes are handled by new/delete - // directly. + // Requests larger than _M_max_bytes are handled by operator + // new/delete directly. __pool_type& __pool = this->_S_get_pool(); const size_t __bytes = __n * sizeof(_Tp); if (__pool._M_check_threshold(__bytes)) diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/tune-2.cc b/libstdc++-v3/testsuite/ext/mt_allocator/tune-2.cc index 60e9b38ebff..1dcf084502b 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/tune-2.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/tune-2.cc @@ -37,13 +37,12 @@ void test02() typedef __gnu_cxx::__mt_alloc allocator_type; typedef __gnu_cxx::__pool_base::_Tune tune_type; - tune_type t_default; tune_type t_opt(16, 5120, 32, 5120, 20, 10, false); tune_type t_single(16, 5120, 32, 5120, 1, 10, false); allocator_type a; - tune_type t1 = a._M_get_options(); - VERIFY( t1._M_align == t_default._M_align ); + tune_type t_default = a._M_get_options(); + tune_type t1 = t_default; a._M_set_options(t_opt); tune_type t2 = a._M_get_options(); VERIFY( t1._M_align != t2._M_align ); diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/tune-3.cc b/libstdc++-v3/testsuite/ext/mt_allocator/tune-3.cc index e1d2105d3af..c7049fc8e23 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/tune-3.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/tune-3.cc @@ -45,13 +45,13 @@ void test03() typedef _Cp policy_type; typedef __gnu_cxx::__mt_alloc allocator_type; - tune_type t_default; tune_type t_opt(16, 5120, 32, 5120, 20, 10, false); tune_type t_single(16, 5120, 32, 5120, 1, 10, false); // First instances assured. allocator_type a; - tune_type t1 = a._M_get_options(); + tune_type t_default = a._M_get_options(); + tune_type t1 = t_default; tune_type t2; if (test_policy::per_type()) { diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/tune-4.cc b/libstdc++-v3/testsuite/ext/mt_allocator/tune-4.cc index da85295a5de..90c0c4a709c 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/tune-4.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/tune-4.cc @@ -38,6 +38,7 @@ struct pod2 { int i; int j; + int k; }; // Tune characteristics, two of different instantiations @@ -51,16 +52,15 @@ void test04() typedef _Cp policy_type; typedef __gnu_cxx::__mt_alloc allocator_type; - tune_type t_default; tune_type t_opt(16, 5120, 32, 5120, 20, 10, false); tune_type t_single(16, 5120, 32, 5120, 1, 10, false); allocator_type a; - tune_type t1 = a._M_get_options(); + tune_type t_default = a._M_get_options(); + tune_type t1 = t_default; tune_type t2; if (test_policy::per_type()) { - VERIFY( t1._M_align == t_default._M_align ); a._M_set_options(t_opt); t2 = a._M_get_options(); VERIFY( t1._M_align != t2._M_align ); @@ -82,7 +82,6 @@ void test04() // Both policy_type and rebind_type::policy_type have same characteristics. if (test_policy::per_type()) { - VERIFY( t3._M_align == t_default._M_align ); a2._M_set_options(t_opt); t4 = a2._M_get_options(); VERIFY( t3._M_align != t4._M_align ); -- 2.11.4.GIT