$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r67753 - sandbox/guild/pool/boost/pool
From: marshall_at_[hidden]
Date: 2011-01-07 11:36:25
Author: marshall
Date: 2011-01-07 11:36:11 EST (Fri, 07 Jan 2011)
New Revision: 67753
URL: http://svn.boost.org/trac/boost/changeset/67753
Log:
Applying patch for bug 2696 to keep trunk and guild in sync
Text files modified: 
   sandbox/guild/pool/boost/pool/object_pool.hpp    |     4 +-                                      
   sandbox/guild/pool/boost/pool/pool.hpp           |    24 ++++++++++++++---                       
   sandbox/guild/pool/boost/pool/pool_alloc.hpp     |    52 +++++++++++++++++++++------------------ 
   sandbox/guild/pool/boost/pool/poolfwd.hpp        |     9 ++++--                                  
   sandbox/guild/pool/boost/pool/singleton_pool.hpp |     3 +                                       
   5 files changed, 57 insertions(+), 35 deletions(-)
Modified: sandbox/guild/pool/boost/pool/object_pool.hpp
==============================================================================
--- sandbox/guild/pool/boost/pool/object_pool.hpp	(original)
+++ sandbox/guild/pool/boost/pool/object_pool.hpp	2011-01-07 11:36:11 EST (Fri, 07 Jan 2011)
@@ -52,8 +52,8 @@
     { return *(static_cast<void **>(ptr)); }
 
   public:
-    explicit object_pool(const size_type next_size = 32)
-    :pool<UserAllocator>(sizeof(T), next_size) { }
+    explicit object_pool(const size_type next_size = 32, const size_type max_size = 0)
+    :pool<UserAllocator>(sizeof(T), next_size, max_size) { }
 
     ~object_pool();
 
Modified: sandbox/guild/pool/boost/pool/pool.hpp
==============================================================================
--- sandbox/guild/pool/boost/pool/pool.hpp	(original)
+++ sandbox/guild/pool/boost/pool/pool.hpp	2011-01-07 11:36:11 EST (Fri, 07 Jan 2011)
@@ -156,6 +156,7 @@
     const size_type requested_size;
     size_type next_size;
     size_type start_size;
+    size_type max_size;
 
     // finds which POD in the list 'chunk' was allocated from
     details::PODptr<size_type> find_POD(void * const chunk) const;
@@ -189,8 +190,9 @@
   public:
     // pre: npartition_size != 0 && nnext_size != 0
     explicit pool(const size_type nrequested_size,
-        const size_type nnext_size = 32)
-    :list(0, 0), requested_size(nrequested_size), next_size(nnext_size), start_size(nnext_size)
+        const size_type nnext_size = 32,
+        const size_type nmax_size = 0)
+    :list(0, 0), requested_size(nrequested_size), next_size(nnext_size), start_size(nnext_size),max_size(nmax_size)
     { }
 
     ~pool() { purge_memory(); }
@@ -206,6 +208,8 @@
 
     size_type get_next_size() const { return next_size; }
     void set_next_size(const size_type nnext_size) { next_size = start_size = nnext_size; }
+    size_type get_max_size() const { return max_size; }
+    void set_max_size(const size_type nmax_size) { max_size = nmax_size; }
     size_type get_requested_size() const { return requested_size; }
 
     // Both malloc and ordered_malloc do a quick inlined check first for any
@@ -434,7 +438,12 @@
   if (ptr == 0)
     return 0;
   const details::PODptr<size_type> node(ptr, POD_size);
-  next_size <<= 1;
+  
+  BOOST_USING_STD_MIN();
+  if(!max_size)
+    next_size <<= 1;
+  else if( next_size*partition_size/requested_size < max_size)
+    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
 
   //  initialize it,
   store().add_block(node.begin(), node.element_size(), partition_size);
@@ -458,13 +467,18 @@
   if (ptr == 0)
     return 0;
   const details::PODptr<size_type> node(ptr, POD_size);
-  next_size <<= 1;
+
+  BOOST_USING_STD_MIN();
+  if(!max_size)
+    next_size <<= 1;
+  else if( next_size*partition_size/requested_size < max_size)
+    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
 
   //  initialize it,
   //  (we can use "add_block" here because we know that
   //  the free list is empty, so we don't have to use
   //  the slower ordered version)
-  store().add_block(node.begin(), node.element_size(), partition_size);
+  store().add_ordered_block(node.begin(), node.element_size(), partition_size);
 
   //  insert it into the list,
   //   handle border case
Modified: sandbox/guild/pool/boost/pool/pool_alloc.hpp
==============================================================================
--- sandbox/guild/pool/boost/pool/pool_alloc.hpp	(original)
+++ sandbox/guild/pool/boost/pool/pool_alloc.hpp	2011-01-07 11:36:11 EST (Fri, 07 Jan 2011)
@@ -35,7 +35,8 @@
 template <typename T,
     typename UserAllocator,
     typename Mutex,
-    unsigned NextSize>
+    unsigned NextSize,
+    unsigned MaxSize>
 class pool_allocator
 {
   public:
@@ -54,7 +55,7 @@
     template <typename U>
     struct rebind
     {
-      typedef pool_allocator<U, UserAllocator, Mutex, NextSize> other;
+      typedef pool_allocator<U, UserAllocator, Mutex, NextSize,MaxSize> other;
     };
 
   public:
@@ -65,7 +66,7 @@
       // initialization. See ticket #2359 for a complete explaination
       // ( http://svn.boost.org/trac/boost/ticket/2359 )
       singleton_pool<pool_allocator_tag, sizeof(T), UserAllocator, Mutex,
-                     NextSize>::is_from(0);
+                     NextSize, MaxSize>::is_from(0);
     }
 
     // default copy constructor
@@ -74,14 +75,14 @@
 
     // not explicit, mimicking std::allocator [20.4.1]
     template <typename U>
-    pool_allocator(const pool_allocator<U, UserAllocator, Mutex, NextSize> &)
+    pool_allocator(const pool_allocator<U, UserAllocator, Mutex, NextSize, MaxSize> &)
     {
       // Required to ensure construction of singleton_pool IFF an
       // instace of this allocator is constructed during global
       // initialization. See ticket #2359 for a complete explaination
       // ( http://svn.boost.org/trac/boost/ticket/2359 )
       singleton_pool<pool_allocator_tag, sizeof(T), UserAllocator, Mutex,
-                     NextSize>::is_from(0);
+                     NextSize, MaxSize>::is_from(0);
     }
 
     // default destructor
@@ -109,7 +110,7 @@
     {
       const pointer ret = static_cast<pointer>(
           singleton_pool<pool_allocator_tag, sizeof(T), UserAllocator, Mutex,
-              NextSize>::ordered_malloc(n) );
+              NextSize, MaxSize>::ordered_malloc(n) );
       if (ret == 0)
         boost::throw_exception(std::bad_alloc());
       return ret;
@@ -123,22 +124,23 @@
         return;
 #endif
       singleton_pool<pool_allocator_tag, sizeof(T), UserAllocator, Mutex,
-          NextSize>::ordered_free(ptr, n);
+          NextSize, MaxSize>::ordered_free(ptr, n);
     }
 };
 
 template<
     typename UserAllocator,
     typename Mutex,
-    unsigned NextSize>
-class pool_allocator<void, UserAllocator, Mutex, NextSize>
+    unsigned NextSize,
+    unsigned MaxSize>
+class pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>
 {
 public:
     typedef void*       pointer;
     typedef const void* const_pointer;
     typedef void        value_type;
     template <class U> struct rebind {
-        typedef pool_allocator<U, UserAllocator, Mutex, NextSize> other;
+        typedef pool_allocator<U, UserAllocator, Mutex, NextSize, MaxSize> other;
     };
 };
 
@@ -147,7 +149,8 @@
 template <typename T,
     typename UserAllocator,
     typename Mutex,
-    unsigned NextSize>
+    unsigned NextSize,
+    unsigned MaxSize>
 class fast_pool_allocator
 {
   public:
@@ -166,7 +169,7 @@
     template <typename U>
     struct rebind
     {
-      typedef fast_pool_allocator<U, UserAllocator, Mutex, NextSize> other;
+      typedef fast_pool_allocator<U, UserAllocator, Mutex, NextSize, MaxSize> other;
     };
 
   public:
@@ -177,7 +180,7 @@
       // initialization. See ticket #2359 for a complete explaination
       // ( http://svn.boost.org/trac/boost/ticket/2359 )
       singleton_pool<fast_pool_allocator_tag, sizeof(T),
-                     UserAllocator, Mutex, NextSize>::is_from(0);
+                     UserAllocator, Mutex, NextSize, MaxSize>::is_from(0);
     }
     
     // default copy constructor
@@ -187,14 +190,14 @@
     // not explicit, mimicking std::allocator [20.4.1]
     template <typename U>
     fast_pool_allocator(
-        const fast_pool_allocator<U, UserAllocator, Mutex, NextSize> &)
+        const fast_pool_allocator<U, UserAllocator, Mutex, NextSize, MaxSize> &)
     {
       // Required to ensure construction of singleton_pool IFF an
       // instace of this allocator is constructed during global
       // initialization. See ticket #2359 for a complete explaination
       // ( http://svn.boost.org/trac/boost/ticket/2359 )
       singleton_pool<fast_pool_allocator_tag, sizeof(T),
-                     UserAllocator, Mutex, NextSize>::is_from(0);
+                     UserAllocator, Mutex, NextSize, MaxSize>::is_from(0);
     }
 
     // default destructor
@@ -223,10 +226,10 @@
       const pointer ret = (n == 1) ? 
           static_cast<pointer>(
               (singleton_pool<fast_pool_allocator_tag, sizeof(T),
-                  UserAllocator, Mutex, NextSize>::malloc)() ) :
+                  UserAllocator, Mutex, NextSize, MaxSize>::malloc)() ) :
           static_cast<pointer>(
               singleton_pool<fast_pool_allocator_tag, sizeof(T),
-                  UserAllocator, Mutex, NextSize>::ordered_malloc(n) );
+                  UserAllocator, Mutex, NextSize, MaxSize>::ordered_malloc(n) );
       if (ret == 0)
         boost::throw_exception(std::bad_alloc());
       return ret;
@@ -237,7 +240,7 @@
     {
       const pointer ret = static_cast<pointer>(
           (singleton_pool<fast_pool_allocator_tag, sizeof(T),
-              UserAllocator, Mutex, NextSize>::malloc)() );
+              UserAllocator, Mutex, NextSize, MaxSize>::malloc)() );
       if (ret == 0)
         boost::throw_exception(std::bad_alloc());
       return ret;
@@ -250,30 +253,31 @@
 #endif
       if (n == 1)
         (singleton_pool<fast_pool_allocator_tag, sizeof(T),
-            UserAllocator, Mutex, NextSize>::free)(ptr);
+            UserAllocator, Mutex, NextSize, MaxSize>::free)(ptr);
       else
         (singleton_pool<fast_pool_allocator_tag, sizeof(T),
-            UserAllocator, Mutex, NextSize>::free)(ptr, n);
+            UserAllocator, Mutex, NextSize, MaxSize>::free)(ptr, n);
     }
     static void deallocate(const pointer ptr)
     {
       (singleton_pool<fast_pool_allocator_tag, sizeof(T),
-          UserAllocator, Mutex, NextSize>::free)(ptr);
+          UserAllocator, Mutex, NextSize, MaxSize>::free)(ptr);
     }
 };
 
 template<
     typename UserAllocator,
     typename Mutex,
-    unsigned NextSize>
-class fast_pool_allocator<void, UserAllocator, Mutex, NextSize>
+    unsigned NextSize,
+    unsigned MaxSize>
+class fast_pool_allocator<void, UserAllocator, Mutex, NextSize, MaxSize>
 {
 public:
     typedef void*       pointer;
     typedef const void* const_pointer;
     typedef void        value_type;
     template <class U> struct rebind {
-        typedef fast_pool_allocator<U, UserAllocator, Mutex, NextSize> other;
+        typedef fast_pool_allocator<U, UserAllocator, Mutex, NextSize, MaxSize> other;
     };
 };
 
Modified: sandbox/guild/pool/boost/pool/poolfwd.hpp
==============================================================================
--- sandbox/guild/pool/boost/pool/poolfwd.hpp	(original)
+++ sandbox/guild/pool/boost/pool/poolfwd.hpp	2011-01-07 11:36:11 EST (Fri, 07 Jan 2011)
@@ -46,7 +46,8 @@
 template <typename Tag, unsigned RequestedSize,
     typename UserAllocator = default_user_allocator_new_delete,
     typename Mutex = details::pool::default_mutex,
-    unsigned NextSize = 32>
+    unsigned NextSize = 32,
+    unsigned MaxSize = 0>
 struct singleton_pool;
 
 //
@@ -57,7 +58,8 @@
 template <typename T,
     typename UserAllocator = default_user_allocator_new_delete,
     typename Mutex = details::pool::default_mutex,
-    unsigned NextSize = 32>
+    unsigned NextSize = 32,
+    unsigned MaxSize = 0>
 class pool_allocator;
 
 struct fast_pool_allocator_tag;
@@ -65,7 +67,8 @@
 template <typename T,
     typename UserAllocator = default_user_allocator_new_delete,
     typename Mutex = details::pool::default_mutex,
-    unsigned NextSize = 32>
+    unsigned NextSize = 32,
+    unsigned MaxSize = 0>
 class fast_pool_allocator;
 
 } // namespace boost
Modified: sandbox/guild/pool/boost/pool/singleton_pool.hpp
==============================================================================
--- sandbox/guild/pool/boost/pool/singleton_pool.hpp	(original)
+++ sandbox/guild/pool/boost/pool/singleton_pool.hpp	2011-01-07 11:36:11 EST (Fri, 07 Jan 2011)
@@ -27,7 +27,8 @@
 template <typename Tag, unsigned RequestedSize,
     typename UserAllocator,
     typename Mutex,
-    unsigned NextSize>
+    unsigned NextSize,
+    unsigned MaxSize>
 struct singleton_pool
 {
   public: