From 6571df13b4c1b52d50a7e297db59ec698c2220ee Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Thu, 28 Oct 2004 20:46:08 +0000 Subject: [PATCH] mt_allocator.h (__common_pool_policy): Add template template parameter for pool class type. 2004-10-28 Benjamin Kosnik * include/ext/mt_allocator.h (__common_pool_policy): Add template template parameter for pool class type. (__per_type_pool_policy): Same. (__mt_allocator): Don't inherit policy. Qualify policy_type calls. * testsuite/ext/mt_allocator/check_deallocate_null.cc: Fix. * testsuite/ext/mt_allocator/check_deallocate_null_thread.cc: Same. * testsuite/ext/mt_allocator/deallocate_global-2.cc: Same. * testsuite/ext/mt_allocator/deallocate_global-4.cc: Same. * testsuite/ext/mt_allocator/deallocate_global_thread-1.cc: Same. * testsuite/ext/mt_allocator/deallocate_global_thread-3.cc: Same. * testsuite/ext/mt_allocator/deallocate_local-2.cc: Same. * testsuite/ext/mt_allocator/deallocate_local-4.cc: Same. * testsuite/ext/mt_allocator/deallocate_local_thread-1.cc: Same. * testsuite/ext/mt_allocator/deallocate_local_thread-3.cc: Same. * testsuite/ext/mt_allocator/instantiate.cc: Same. * testsuite/ext/mt_allocator/tune-1.cc: Same. * testsuite/ext/mt_allocator/tune-2.cc: Same. * testsuite/ext/mt_allocator/tune-3.cc: Same. * testsuite/ext/mt_allocator/tune-4.cc: Same. From-SVN: r89776 --- libstdc++-v3/ChangeLog | 22 ++ libstdc++-v3/include/ext/mt_allocator.h | 362 ++++++++---------- .../ext/mt_allocator/check_deallocate_null.cc | 3 +- .../check_deallocate_null_thread.cc | 3 +- .../ext/mt_allocator/deallocate_global-2.cc | 4 +- .../ext/mt_allocator/deallocate_global-4.cc | 4 +- .../deallocate_global_thread-1.cc | 4 +- .../deallocate_global_thread-3.cc | 4 +- .../ext/mt_allocator/deallocate_local-2.cc | 3 +- .../ext/mt_allocator/deallocate_local-4.cc | 4 +- .../mt_allocator/deallocate_local_thread-1.cc | 3 +- .../mt_allocator/deallocate_local_thread-3.cc | 4 +- .../testsuite/ext/mt_allocator/instantiate.cc | 8 +- .../testsuite/ext/mt_allocator/tune-1.cc | 8 +- .../testsuite/ext/mt_allocator/tune-2.cc | 8 +- .../testsuite/ext/mt_allocator/tune-3.cc | 24 +- .../testsuite/ext/mt_allocator/tune-4.cc | 24 +- 17 files changed, 259 insertions(+), 233 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0d1c4c08886..561c3670dc6 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,25 @@ +2004-10-28 Benjamin Kosnik + + * include/ext/mt_allocator.h (__common_pool_policy): Add template + template parameter for pool class type. + (__per_type_pool_policy): Same. + (__mt_allocator): Don't inherit policy. Qualify policy_type calls. + * testsuite/ext/mt_allocator/check_deallocate_null.cc: Fix. + * testsuite/ext/mt_allocator/check_deallocate_null_thread.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global-2.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global-4.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global_thread-1.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global_thread-3.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local-2.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local-4.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local_thread-1.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local_thread-3.cc: Same. + * testsuite/ext/mt_allocator/instantiate.cc: Same. + * testsuite/ext/mt_allocator/tune-1.cc: Same. + * testsuite/ext/mt_allocator/tune-2.cc: Same. + * testsuite/ext/mt_allocator/tune-3.cc: Same. + * testsuite/ext/mt_allocator/tune-4.cc: Same. + 2004-10-28 Paolo Carlini * include/bits/locale_facets.tcc (num_get<>::_M_extract_float): diff --git a/libstdc++-v3/include/ext/mt_allocator.h b/libstdc++-v3/include/ext/mt_allocator.h index 6649111a6e7..e5dab29e6d8 100644 --- a/libstdc++-v3/include/ext/mt_allocator.h +++ b/libstdc++-v3/include/ext/mt_allocator.h @@ -65,7 +65,7 @@ namespace __gnu_cxx // Variables used to configure the behavior of the allocator, // assigned and explained in detail below. struct _Tune - { + { // Compile time constants for the default _Tune values. enum { _S_align = 8 }; enum { _S_max_bytes = 128 }; @@ -129,19 +129,6 @@ namespace __gnu_cxx _M_chunk_size(__chunk), _M_max_threads(__maxthreads), _M_freelist_headroom(__headroom), _M_force_new(__force) { } - - bool - is_default() const - { - bool __ret = true; - __ret &= _M_align == _S_align; - __ret &= _M_max_bytes == _S_max_bytes; - __ret &= _M_min_bin == _S_min_bin; - __ret &= _M_chunk_size == _S_chunk_size; - __ret &= _M_max_threads == _S_max_threads; - __ret &= _M_freelist_headroom == _S_freelist_headroom; - return __ret; - } }; struct _Block_address @@ -173,11 +160,20 @@ namespace __gnu_cxx _M_get_align() { return _M_options._M_align; } - explicit __pool_base() + 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) { } + explicit + __pool_base(const _Tune& __options) + : _M_options(__options), _M_binmap(NULL), _M_init(false) { } + + private: + explicit + __pool_base(const __pool_base&); + + __pool_base& + operator=(const __pool_base&); protected: // Configuration options. @@ -185,8 +181,9 @@ namespace __gnu_cxx _Binmap_type* _M_binmap; - // We need to create the initial lists and set up some variables - // before we can answer to the first request for memory. + // Configuration of the pool object via _M_options can happen + // after construction but before initialization. After + // initialization is complete, this variable is set to true. bool _M_init; }; @@ -201,9 +198,74 @@ namespace __gnu_cxx template<> class __pool; + // Specialization for single thread. + template<> + class __pool : public __pool_base + { + public: + union _Block_record + { + // Points to the block_record of the next free block. + _Block_record* volatile _M_next; + }; + + struct _Bin_record + { + // An "array" of pointers to the first free block. + _Block_record** volatile _M_first; + // A list of the initial addresses of all allocated blocks. + _Block_address* _M_address; + }; + + void + _M_initialize_once() + { + if (__builtin_expect(_M_init == false, false)) + _M_initialize(); + } + + void + _M_destroy() throw(); + + char* + _M_reserve_block(size_t __bytes, const size_t __thread_id); + + void + _M_reclaim_block(char* __p, size_t __bytes); + + size_t + _M_get_thread_id() { return 0; } + + const _Bin_record& + _M_get_bin(size_t __which) + { return _M_bin[__which]; } + + void + _M_adjust_freelist(const _Bin_record&, _Block_record*, size_t) + { } + + 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) { } + + private: + // An "array" of bin_records each of which represents a specific + // power of 2 size. Memory to this "array" is allocated in + // _M_initialize(). + _Bin_record* volatile _M_bin; + + // Actual value calculated in _M_initialize(). + size_t _M_bin_size; + + void + _M_initialize(); + }; + #ifdef __GTHREADS - // Specialization for thread enabled, via gthreads.h. + // Specialization for thread enabled, via gthreads.h. template<> class __pool : public __pool_base { @@ -326,8 +388,6 @@ namespace __gnu_cxx _M_once = __tmp; } - ~__pool() { } - private: // An "array" of bin_records each of which represents a specific // power of 2 size. Memory to this "array" is allocated in @@ -344,94 +404,24 @@ namespace __gnu_cxx }; #endif - // Specialization for single thread. - template<> - class __pool : public __pool_base - { - public: - union _Block_record - { - // Points to the block_record of the next free block. - _Block_record* volatile _M_next; - }; - - struct _Bin_record - { - // An "array" of pointers to the first free block. - _Block_record** volatile _M_first; - // A list of the initial addresses of all allocated blocks. - _Block_address* _M_address; - }; - - void - _M_initialize_once() - { - if (__builtin_expect(_M_init == false, false)) - _M_initialize(); - } + template