Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71772 - sandbox/block_ptr/boost/detail
From: phil_at_[hidden]
Date: 2011-05-06 18:19:54


Author: pbouchard
Date: 2011-05-06 18:19:54 EDT (Fri, 06 May 2011)
New Revision: 71772
URL: http://svn.boost.org/trac/boost/changeset/71772

Log:
* Reactivated thread_ptr in pool
Text files modified:
   sandbox/block_ptr/boost/detail/block_base.hpp | 39 +++++++++++++++++++++++++++++++--------
   1 files changed, 31 insertions(+), 8 deletions(-)

Modified: sandbox/block_ptr/boost/detail/block_base.hpp
==============================================================================
--- sandbox/block_ptr/boost/detail/block_base.hpp (original)
+++ sandbox/block_ptr/boost/detail/block_base.hpp 2011-05-06 18:19:54 EDT (Fri, 06 May 2011)
@@ -75,8 +75,13 @@
 
         typedef std::list< numeric::interval<long>, fast_pool_allocator< numeric::interval<long> > > pool_lii; /**< Syntax helper. */
 
- static pool_lii plii_; /**< List of memory boundaries. */
+ //static pool_lii plii_; /**< List of memory boundaries. */
 
+#ifndef BOOST_DISABLE_THREADS
+ static thread_specific_ptr<pool_lii> plii_; /**< Thread specific list of memory boundaries. */
+#else
+ static std::auto_ptr<pool_lii> plii_; /**< List of memory boundaries. */
+#endif
 
         /**
                 Tells whether a pointer is part of the pool or not.
@@ -90,6 +95,12 @@
                 return pool_t::is_from(p);
         }
         
+ static void init()
+ {
+ if (plii_.get() == 0)
+ plii_.reset(new pool_lii());
+ }
+
         /**
                 Tracks the memory boundaries where a pointer belongs to. Also gets rid of the boundaries that were allocated before the pointer was allocated.
                 
@@ -103,15 +114,17 @@
         mutex::scoped_lock scoped_lock(pool_mutex_);
 #endif
 
+ init();
+
         pool_lii::reverse_iterator i;
         
- for (i = plii_.rbegin(); i != plii_.rend(); i ++)
+ for (i = plii_->rbegin(); i != plii_->rend(); i ++)
             if (in((long)(p), * i))
                 break;
 
- plii_.erase(i.base(), plii_.end());
+ plii_->erase(i.base(), plii_->end());
         
- return (block_base *)(plii_.rbegin()->lower());
+ return (block_base *)(plii_->rbegin()->lower());
     }
     
         
@@ -128,9 +141,11 @@
         mutex::scoped_lock scoped_lock(pool_mutex_);
 #endif
 
+ init();
+
         void * p = pool_t::ordered_malloc(s);
         
- plii_.push_back(numeric::interval<long>((long) p, long((char *)(p) + s)));
+ plii_->push_back(numeric::interval<long>((long) p, long((char *)(p) + s)));
         
         return p;
     }
@@ -149,18 +164,26 @@
         mutex::scoped_lock scoped_lock(pool_mutex_);
 #endif
 
+ init();
+
         pool_lii::reverse_iterator i;
         
- for (i = plii_.rbegin(); i != plii_.rend(); i ++)
+ for (i = plii_->rbegin(); i != plii_->rend(); i ++)
             if (in((long)(p), * i))
                 break;
 
- plii_.erase(i.base(), plii_.end());
+ plii_->erase(i.base(), plii_->end());
         pool_t::ordered_free(p, s);
     }
 };
 
-pool::pool_lii pool::plii_;
+//pool::pool_lii pool::plii_;
+
+#ifndef BOOST_DISABLE_THREADS
+thread_specific_ptr<pool::pool_lii> pool::plii_;
+#else
+std::auto_ptr<pool::pool_lii> pool::plii_;
+#endif
 
 #ifndef BOOST_DISABLE_THREADS
 mutex pool::pool_mutex_;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk