Boost logo

Boost-Commit :

From: pdimov_at_[hidden]
Date: 2008-07-12 07:57:45


Author: pdimov
Date: 2008-07-12 07:57:45 EDT (Sat, 12 Jul 2008)
New Revision: 47349
URL: http://svn.boost.org/trac/boost/changeset/47349

Log:
Merged 44636, 44640, 45094 (atomic access) from trunk to release.
Added:
   branches/release/boost/memory_order.hpp
      - copied unchanged from r44636, /trunk/boost/memory_order.hpp
   branches/release/libs/smart_ptr/test/sp_atomic_mt2_test.cpp
      - copied unchanged from r45094, /trunk/libs/smart_ptr/test/sp_atomic_mt2_test.cpp
   branches/release/libs/smart_ptr/test/sp_atomic_mt_test.cpp
      - copied, changed from r44640, /trunk/libs/smart_ptr/test/sp_atomic_mt_test.cpp
   branches/release/libs/smart_ptr/test/sp_atomic_test.cpp
      - copied unchanged from r44636, /trunk/libs/smart_ptr/test/sp_atomic_test.cpp
Text files modified:
   branches/release/boost/shared_ptr.hpp | 64 ++++++++++++++++++++++++++++++++++++++++
   branches/release/libs/smart_ptr/test/Jamfile.v2 | 1
   branches/release/libs/smart_ptr/test/sp_atomic_mt_test.cpp | 7 ++++
   3 files changed, 72 insertions(+), 0 deletions(-)

Modified: branches/release/boost/shared_ptr.hpp
==============================================================================
--- branches/release/boost/shared_ptr.hpp (original)
+++ branches/release/boost/shared_ptr.hpp 2008-07-12 07:57:45 EDT (Sat, 12 Jul 2008)
@@ -33,6 +33,11 @@
 #include <boost/detail/workaround.hpp>
 #include <boost/detail/sp_convertible.hpp>
 
+#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
+#include <boost/detail/spinlock_pool.hpp>
+#include <boost/memory_order.hpp>
+#endif
+
 #include <algorithm> // for std::swap
 #include <functional> // for std::less
 #include <typeinfo> // for std::bad_cast
@@ -498,6 +503,65 @@
         return pn.get_deleter( ti );
     }
 
+ // atomic access
+
+#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
+
+ shared_ptr<T> atomic_load( memory_order /*mo*/ = memory_order_seq_cst ) const
+ {
+ boost::detail::spinlock_pool<2>::scoped_lock lock( this );
+ return *this;
+ }
+
+ void atomic_store( shared_ptr<T> r, memory_order /*mo*/ = memory_order_seq_cst )
+ {
+ boost::detail::spinlock_pool<2>::scoped_lock lock( this );
+ swap( r );
+ }
+
+ shared_ptr<T> atomic_swap( shared_ptr<T> r, memory_order /*mo*/ = memory_order_seq_cst )
+ {
+ boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( this );
+
+ sp.lock();
+ swap( r );
+ sp.unlock();
+
+ return r; // return std::move(r)
+ }
+
+ bool atomic_compare_swap( shared_ptr<T> & v, shared_ptr<T> w )
+ {
+ boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( this );
+
+ sp.lock();
+
+ if( px == v.px && pn == v.pn )
+ {
+ swap( w );
+
+ sp.unlock();
+
+ return true;
+ }
+ else
+ {
+ shared_ptr tmp( *this );
+
+ sp.unlock();
+
+ tmp.swap( v );
+ return false;
+ }
+ }
+
+ inline bool atomic_compare_swap( shared_ptr<T> & v, shared_ptr<T> w, memory_order /*success*/, memory_order /*failure*/ )
+ {
+ return atomic_compare_swap( v, w ); // std::move( w )
+ }
+
+#endif
+
 // Tasteless as this may seem, making all members public allows member templates
 // to work in the absence of member template friends. (Matthew Langston)
 

Modified: branches/release/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- branches/release/libs/smart_ptr/test/Jamfile.v2 (original)
+++ branches/release/libs/smart_ptr/test/Jamfile.v2 2008-07-12 07:57:45 EDT (Sat, 12 Jul 2008)
@@ -47,5 +47,6 @@
           [ run wp_convertible_test.cpp ]
           [ run ip_convertible_test.cpp ]
           [ run allocate_shared_test.cpp ]
+ [ run sp_atomic_test.cpp ]
         ;
 }

Copied: branches/release/libs/smart_ptr/test/sp_atomic_mt_test.cpp (from r44640, /trunk/libs/smart_ptr/test/sp_atomic_mt_test.cpp)
==============================================================================
--- /trunk/libs/smart_ptr/test/sp_atomic_mt_test.cpp (original)
+++ branches/release/libs/smart_ptr/test/sp_atomic_mt_test.cpp 2008-07-12 07:57:45 EDT (Sat, 12 Jul 2008)
@@ -1,3 +1,10 @@
+
+// Copyright (c) 2008 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+
 //#define USE_MUTEX
 //#define USE_RWLOCK
 


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