Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71966 - sandbox/block_ptr/boost
From: phil_at_[hidden]
Date: 2011-05-16 01:19:56


Author: pbouchard
Date: 2011-05-16 01:19:51 EDT (Mon, 16 May 2011)
New Revision: 71966
URL: http://svn.boost.org/trac/boost/changeset/71966

Log:
* Now thread safe
Text files modified:
   sandbox/block_ptr/boost/block_ptr.hpp | 27 ++++++++++++++-------------
   1 files changed, 14 insertions(+), 13 deletions(-)

Modified: sandbox/block_ptr/boost/block_ptr.hpp
==============================================================================
--- sandbox/block_ptr/boost/block_ptr.hpp (original)
+++ sandbox/block_ptr/boost/block_ptr.hpp 2011-05-16 01:19:51 EDT (Mon, 16 May 2011)
@@ -66,7 +66,7 @@
     typedef detail::atomic_count count_type;
 
 #ifndef BOOST_DISABLE_THREADS
- mutable mutex mutex_;
+ static mutex mutex_;
 #endif
 
     count_type count_; /**< Count of the number of pointers from the stack referencing the same @c block_header .*/
@@ -104,10 +104,6 @@
     {
         if (-- count_ == 0)
         {
-#ifndef BOOST_DISABLE_THREADS
- mutex::scoped_lock scoped_lock(mutex_);
-#endif
-
                         destroy_ = true;
                         
             for (intrusive_list::iterator<block_base, & block_base::block_tag_> i; i = elements_.begin(), i != elements_.end(); )
@@ -159,10 +155,6 @@
             
         if (redir_ != q)
         {
-#ifndef BOOST_DISABLE_THREADS
- mutex::scoped_lock scoped_lock(mutex_);
-#endif
-
             redir_ = q;
             redir_->includes_.merge(includes_);
             redir_->elements_.merge(elements_);
@@ -217,6 +209,7 @@
 };
 
 #ifndef BOOST_DISABLE_THREADS
+mutex block_header::mutex_;
 mutex block_header::pool_mutex_;
 #endif
 fast_pool_allocator<block_header> block_header::pool_;
@@ -368,6 +361,10 @@
         template <typename V>
             block_ptr & operator = (block_ptr<V> const & p)
             {
+#ifndef BOOST_DISABLE_THREADS
+ mutex::scoped_lock scoped_lock(block_header::mutex_);
+#endif
+
                 if (ps_->redir() != p.ps_->redir())
                 {
                     release(false);
@@ -393,6 +390,10 @@
 
         void reset()
         {
+#ifndef BOOST_DISABLE_THREADS
+ mutex::scoped_lock scoped_lock(block_header::mutex_);
+#endif
+
             release(false);
         }
         
@@ -403,6 +404,10 @@
 
         ~block_ptr()
         {
+#ifndef BOOST_DISABLE_THREADS
+ mutex::scoped_lock scoped_lock(block_header::mutex_);
+#endif
+
                         if (cyclic())
                                 base::po_ = 0;
                         else
@@ -452,10 +457,6 @@
 
                     block_header * q = ps_->redir();
             
-#ifndef BOOST_DISABLE_THREADS
- mutex::scoped_lock scoped_lock(q->mutex_);
-#endif
-
                         // iterate memory blocks
             for (intrusive_list::iterator<block_base, & block_base::init_tag_> i = p->inits_.begin(); i != p->inits_.end(); ++ i)
             {


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