imgtools/imglib/boostlibrary/boost/smart_ptr/shared_ptr.hpp
changeset 0 044383f39525
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
       
     2 #define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
       
     3 
       
     4 //
       
     5 //  shared_ptr.hpp
       
     6 //
       
     7 //  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
       
     8 //  Copyright (c) 2001-2008 Peter Dimov
       
     9 //
       
    10 //  Distributed under the Boost Software License, Version 1.0. (See
       
    11 //  accompanying file LICENSE_1_0.txt or copy at
       
    12 //  http://www.boost.org/LICENSE_1_0.txt)
       
    13 //
       
    14 //  See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.
       
    15 //
       
    16 
       
    17 #include <boost/config.hpp>   // for broken compiler workarounds
       
    18 
       
    19 #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
       
    20 #include <boost/smart_ptr/detail/shared_ptr_nmt.hpp>
       
    21 #else
       
    22 
       
    23 // In order to avoid circular dependencies with Boost.TR1
       
    24 // we make sure that our include of <memory> doesn't try to
       
    25 // pull in the TR1 headers: that's why we use this header 
       
    26 // rather than including <memory> directly:
       
    27 #include <boost/config/no_tr1/memory.hpp>  // std::auto_ptr
       
    28 
       
    29 #include <boost/assert.hpp>
       
    30 #include <boost/checked_delete.hpp>
       
    31 #include <boost/throw_exception.hpp>
       
    32 #include <boost/smart_ptr/detail/shared_count.hpp>
       
    33 #include <boost/detail/workaround.hpp>
       
    34 #include <boost/smart_ptr/detail/sp_convertible.hpp>
       
    35 
       
    36 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
       
    37 #include <boost/smart_ptr/detail/spinlock_pool.hpp>
       
    38 #include <boost/memory_order.hpp>
       
    39 #endif
       
    40 
       
    41 #include <algorithm>            // for std::swap
       
    42 #include <functional>           // for std::less
       
    43 #include <typeinfo>             // for std::bad_cast
       
    44 
       
    45 #if !defined(BOOST_NO_IOSTREAM)
       
    46 #if !defined(BOOST_NO_IOSFWD)
       
    47 #include <iosfwd>               // for std::basic_ostream
       
    48 #else
       
    49 #include <ostream>
       
    50 #endif
       
    51 #endif
       
    52 
       
    53 #ifdef BOOST_MSVC  // moved here to work around VC++ compiler crash
       
    54 # pragma warning(push)
       
    55 # pragma warning(disable:4284) // odd return type for operator->
       
    56 #endif
       
    57 
       
    58 namespace boost
       
    59 {
       
    60 
       
    61 template<class T> class shared_ptr;
       
    62 template<class T> class weak_ptr;
       
    63 template<class T> class enable_shared_from_this;
       
    64 
       
    65 namespace detail
       
    66 {
       
    67 
       
    68 struct static_cast_tag {};
       
    69 struct const_cast_tag {};
       
    70 struct dynamic_cast_tag {};
       
    71 struct polymorphic_cast_tag {};
       
    72 
       
    73 template<class T> struct shared_ptr_traits
       
    74 {
       
    75     typedef T & reference;
       
    76 };
       
    77 
       
    78 template<> struct shared_ptr_traits<void>
       
    79 {
       
    80     typedef void reference;
       
    81 };
       
    82 
       
    83 #if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
       
    84 
       
    85 template<> struct shared_ptr_traits<void const>
       
    86 {
       
    87     typedef void reference;
       
    88 };
       
    89 
       
    90 template<> struct shared_ptr_traits<void volatile>
       
    91 {
       
    92     typedef void reference;
       
    93 };
       
    94 
       
    95 template<> struct shared_ptr_traits<void const volatile>
       
    96 {
       
    97     typedef void reference;
       
    98 };
       
    99 
       
   100 #endif
       
   101 
       
   102 // enable_shared_from_this support
       
   103 
       
   104 template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> const * ppx, Y const * py, boost::enable_shared_from_this< T > const * pe )
       
   105 {
       
   106     if( pe != 0 )
       
   107     {
       
   108         pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
       
   109     }
       
   110 }
       
   111 
       
   112 #ifdef _MANAGED
       
   113 
       
   114 // Avoid C4793, ... causes native code generation
       
   115 
       
   116 struct sp_any_pointer
       
   117 {
       
   118     template<class T> sp_any_pointer( T* ) {}
       
   119 };
       
   120 
       
   121 inline void sp_enable_shared_from_this( sp_any_pointer, sp_any_pointer, sp_any_pointer )
       
   122 {
       
   123 }
       
   124 
       
   125 #else // _MANAGED
       
   126 
       
   127 inline void sp_enable_shared_from_this( ... )
       
   128 {
       
   129 }
       
   130 
       
   131 #endif // _MANAGED
       
   132 
       
   133 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )
       
   134 
       
   135 // rvalue auto_ptr support based on a technique by Dave Abrahams
       
   136 
       
   137 template< class T, class R > struct sp_enable_if_auto_ptr
       
   138 {
       
   139 };
       
   140 
       
   141 template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
       
   142 {
       
   143     typedef R type;
       
   144 }; 
       
   145 
       
   146 #endif
       
   147 
       
   148 } // namespace detail
       
   149 
       
   150 
       
   151 //
       
   152 //  shared_ptr
       
   153 //
       
   154 //  An enhanced relative of scoped_ptr with reference counted copy semantics.
       
   155 //  The object pointed to is deleted when the last shared_ptr pointing to it
       
   156 //  is destroyed or reset.
       
   157 //
       
   158 
       
   159 template<class T> class shared_ptr
       
   160 {
       
   161 private:
       
   162 
       
   163     // Borland 5.5.1 specific workaround
       
   164     typedef shared_ptr<T> this_type;
       
   165 
       
   166 public:
       
   167 
       
   168     typedef T element_type;
       
   169     typedef T value_type;
       
   170     typedef T * pointer;
       
   171     typedef typename boost::detail::shared_ptr_traits<T>::reference reference;
       
   172 
       
   173     shared_ptr(): px(0), pn() // never throws in 1.30+
       
   174     {
       
   175     }
       
   176 
       
   177     template<class Y>
       
   178     explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
       
   179     {
       
   180         boost::detail::sp_enable_shared_from_this( this, p, p );
       
   181     }
       
   182 
       
   183     //
       
   184     // Requirements: D's copy constructor must not throw
       
   185     //
       
   186     // shared_ptr will release p by calling d(p)
       
   187     //
       
   188 
       
   189     template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d)
       
   190     {
       
   191         boost::detail::sp_enable_shared_from_this( this, p, p );
       
   192     }
       
   193 
       
   194     // As above, but with allocator. A's copy constructor shall not throw.
       
   195 
       
   196     template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
       
   197     {
       
   198         boost::detail::sp_enable_shared_from_this( this, p, p );
       
   199     }
       
   200 
       
   201 //  generated copy constructor, destructor are fine
       
   202 
       
   203     template<class Y>
       
   204     explicit shared_ptr(weak_ptr<Y> const & r): pn(r.pn) // may throw
       
   205     {
       
   206         // it is now safe to copy r.px, as pn(r.pn) did not throw
       
   207         px = r.px;
       
   208     }
       
   209 
       
   210     template<class Y>
       
   211     shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag ): px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() ) // never throws
       
   212     {
       
   213         if( !pn.empty() )
       
   214         {
       
   215             px = r.px;
       
   216         }
       
   217     }
       
   218 
       
   219     template<class Y>
       
   220 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
       
   221 
       
   222     shared_ptr( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
       
   223 
       
   224 #else
       
   225 
       
   226     shared_ptr( shared_ptr<Y> const & r )
       
   227 
       
   228 #endif
       
   229     : px( r.px ), pn( r.pn ) // never throws
       
   230     {
       
   231     }
       
   232 
       
   233     // aliasing
       
   234     template< class Y >
       
   235     shared_ptr( shared_ptr<Y> const & r, T * p ): px( p ), pn( r.pn ) // never throws
       
   236     {
       
   237     }
       
   238 
       
   239     template<class Y>
       
   240     shared_ptr(shared_ptr<Y> const & r, boost::detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)
       
   241     {
       
   242     }
       
   243 
       
   244     template<class Y>
       
   245     shared_ptr(shared_ptr<Y> const & r, boost::detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
       
   246     {
       
   247     }
       
   248 
       
   249     template<class Y>
       
   250     shared_ptr(shared_ptr<Y> const & r, boost::detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
       
   251     {
       
   252         if(px == 0) // need to allocate new counter -- the cast failed
       
   253         {
       
   254             pn = boost::detail::shared_count();
       
   255         }
       
   256     }
       
   257 
       
   258     template<class Y>
       
   259     shared_ptr(shared_ptr<Y> const & r, boost::detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
       
   260     {
       
   261         if(px == 0)
       
   262         {
       
   263             boost::throw_exception(std::bad_cast());
       
   264         }
       
   265     }
       
   266 
       
   267 #ifndef BOOST_NO_AUTO_PTR
       
   268 
       
   269     template<class Y>
       
   270     explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
       
   271     {
       
   272         Y * tmp = r.get();
       
   273         pn = boost::detail::shared_count(r);
       
   274         boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
       
   275     }
       
   276 
       
   277 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
       
   278 
       
   279     template<class Ap>
       
   280     explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
       
   281     {
       
   282         typename Ap::element_type * tmp = r.get();
       
   283         pn = boost::detail::shared_count( r );
       
   284         boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
       
   285     }
       
   286 
       
   287 
       
   288 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
       
   289 
       
   290 #endif // BOOST_NO_AUTO_PTR
       
   291 
       
   292     // assignment
       
   293 
       
   294     shared_ptr & operator=( shared_ptr const & r ) // never throws
       
   295     {
       
   296         this_type(r).swap(*this);
       
   297         return *this;
       
   298     }
       
   299 
       
   300 #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
       
   301 
       
   302     template<class Y>
       
   303     shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
       
   304     {
       
   305         this_type(r).swap(*this);
       
   306         return *this;
       
   307     }
       
   308 
       
   309 #endif
       
   310 
       
   311 #ifndef BOOST_NO_AUTO_PTR
       
   312 
       
   313     template<class Y>
       
   314     shared_ptr & operator=( std::auto_ptr<Y> & r )
       
   315     {
       
   316         this_type(r).swap(*this);
       
   317         return *this;
       
   318     }
       
   319 
       
   320 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
       
   321 
       
   322     template<class Ap>
       
   323     typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
       
   324     {
       
   325         this_type( r ).swap( *this );
       
   326         return *this;
       
   327     }
       
   328 
       
   329 
       
   330 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
       
   331 
       
   332 #endif // BOOST_NO_AUTO_PTR
       
   333 
       
   334 // Move support
       
   335 
       
   336 #if defined( BOOST_HAS_RVALUE_REFS )
       
   337 
       
   338     shared_ptr( shared_ptr && r ): px( r.px ), pn() // never throws
       
   339     {
       
   340         pn.swap( r.pn );
       
   341         r.px = 0;
       
   342     }
       
   343 
       
   344     template<class Y>
       
   345 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
       
   346 
       
   347     shared_ptr( shared_ptr<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
       
   348 
       
   349 #else
       
   350 
       
   351     shared_ptr( shared_ptr<Y> && r )
       
   352 
       
   353 #endif
       
   354     : px( r.px ), pn() // never throws
       
   355     {
       
   356         pn.swap( r.pn );
       
   357         r.px = 0;
       
   358     }
       
   359 
       
   360     shared_ptr & operator=( shared_ptr && r ) // never throws
       
   361     {
       
   362         this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
       
   363         return *this;
       
   364     }
       
   365 
       
   366     template<class Y>
       
   367     shared_ptr & operator=( shared_ptr<Y> && r ) // never throws
       
   368     {
       
   369         this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
       
   370         return *this;
       
   371     }
       
   372 
       
   373 #endif
       
   374 
       
   375     void reset() // never throws in 1.30+
       
   376     {
       
   377         this_type().swap(*this);
       
   378     }
       
   379 
       
   380     template<class Y> void reset(Y * p) // Y must be complete
       
   381     {
       
   382         BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
       
   383         this_type(p).swap(*this);
       
   384     }
       
   385 
       
   386     template<class Y, class D> void reset( Y * p, D d )
       
   387     {
       
   388         this_type( p, d ).swap( *this );
       
   389     }
       
   390 
       
   391     template<class Y, class D, class A> void reset( Y * p, D d, A a )
       
   392     {
       
   393         this_type( p, d, a ).swap( *this );
       
   394     }
       
   395 
       
   396     template<class Y> void reset( shared_ptr<Y> const & r, T * p )
       
   397     {
       
   398         this_type( r, p ).swap( *this );
       
   399     }
       
   400 
       
   401     reference operator* () const // never throws
       
   402     {
       
   403         BOOST_ASSERT(px != 0);
       
   404         return *px;
       
   405     }
       
   406 
       
   407     T * operator-> () const // never throws
       
   408     {
       
   409         BOOST_ASSERT(px != 0);
       
   410         return px;
       
   411     }
       
   412 
       
   413     T * get() const // never throws
       
   414     {
       
   415         return px;
       
   416     }
       
   417 
       
   418 // implicit conversion to "bool"
       
   419 #include <boost/smart_ptr/detail/operator_bool.hpp>
       
   420 
       
   421     bool unique() const // never throws
       
   422     {
       
   423         return pn.unique();
       
   424     }
       
   425 
       
   426     long use_count() const // never throws
       
   427     {
       
   428         return pn.use_count();
       
   429     }
       
   430 
       
   431     void swap(shared_ptr<T> & other) // never throws
       
   432     {
       
   433         std::swap(px, other.px);
       
   434         pn.swap(other.pn);
       
   435     }
       
   436 
       
   437     template<class Y> bool _internal_less(shared_ptr<Y> const & rhs) const
       
   438     {
       
   439         return pn < rhs.pn;
       
   440     }
       
   441 
       
   442     void * _internal_get_deleter( detail::sp_typeinfo const & ti ) const
       
   443     {
       
   444         return pn.get_deleter( ti );
       
   445     }
       
   446 
       
   447     bool _internal_equiv( shared_ptr const & r ) const
       
   448     {
       
   449         return px == r.px && pn == r.pn;
       
   450     }
       
   451 
       
   452 // Tasteless as this may seem, making all members public allows member templates
       
   453 // to work in the absence of member template friends. (Matthew Langston)
       
   454 
       
   455 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
       
   456 
       
   457 private:
       
   458 
       
   459     template<class Y> friend class shared_ptr;
       
   460     template<class Y> friend class weak_ptr;
       
   461 
       
   462 
       
   463 #endif
       
   464 
       
   465     T * px;                     // contained pointer
       
   466     boost::detail::shared_count pn;    // reference counter
       
   467 
       
   468 };  // shared_ptr
       
   469 
       
   470 template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b)
       
   471 {
       
   472     return a.get() == b.get();
       
   473 }
       
   474 
       
   475 template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b)
       
   476 {
       
   477     return a.get() != b.get();
       
   478 }
       
   479 
       
   480 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
       
   481 
       
   482 // Resolve the ambiguity between our op!= and the one in rel_ops
       
   483 
       
   484 template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b)
       
   485 {
       
   486     return a.get() != b.get();
       
   487 }
       
   488 
       
   489 #endif
       
   490 
       
   491 template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b)
       
   492 {
       
   493     return a._internal_less(b);
       
   494 }
       
   495 
       
   496 template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
       
   497 {
       
   498     a.swap(b);
       
   499 }
       
   500 
       
   501 template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r)
       
   502 {
       
   503     return shared_ptr<T>(r, boost::detail::static_cast_tag());
       
   504 }
       
   505 
       
   506 template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r)
       
   507 {
       
   508     return shared_ptr<T>(r, boost::detail::const_cast_tag());
       
   509 }
       
   510 
       
   511 template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)
       
   512 {
       
   513     return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
       
   514 }
       
   515 
       
   516 // shared_*_cast names are deprecated. Use *_pointer_cast instead.
       
   517 
       
   518 template<class T, class U> shared_ptr<T> shared_static_cast(shared_ptr<U> const & r)
       
   519 {
       
   520     return shared_ptr<T>(r, boost::detail::static_cast_tag());
       
   521 }
       
   522 
       
   523 template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
       
   524 {
       
   525     return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
       
   526 }
       
   527 
       
   528 template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r)
       
   529 {
       
   530     return shared_ptr<T>(r, boost::detail::polymorphic_cast_tag());
       
   531 }
       
   532 
       
   533 template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r)
       
   534 {
       
   535     BOOST_ASSERT(dynamic_cast<T *>(r.get()) == r.get());
       
   536     return shared_static_cast<T>(r);
       
   537 }
       
   538 
       
   539 // get_pointer() enables boost::mem_fn to recognize shared_ptr
       
   540 
       
   541 template<class T> inline T * get_pointer(shared_ptr<T> const & p)
       
   542 {
       
   543     return p.get();
       
   544 }
       
   545 
       
   546 // operator<<
       
   547 
       
   548 #if !defined(BOOST_NO_IOSTREAM)
       
   549 
       
   550 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) &&  (__GNUC__ < 3) )
       
   551 
       
   552 template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p)
       
   553 {
       
   554     os << p.get();
       
   555     return os;
       
   556 }
       
   557 
       
   558 #else
       
   559 
       
   560 // in STLport's no-iostreams mode no iostream symbols can be used
       
   561 #ifndef _STLP_NO_IOSTREAMS
       
   562 
       
   563 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
       
   564 // MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
       
   565 using std::basic_ostream;
       
   566 template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p)
       
   567 # else
       
   568 template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p)
       
   569 # endif
       
   570 {
       
   571     os << p.get();
       
   572     return os;
       
   573 }
       
   574 
       
   575 #endif // _STLP_NO_IOSTREAMS
       
   576 
       
   577 #endif // __GNUC__ < 3
       
   578 
       
   579 #endif // !defined(BOOST_NO_IOSTREAM)
       
   580 
       
   581 // get_deleter
       
   582 
       
   583 #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
       
   584     ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
       
   585     ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
       
   586 
       
   587 // g++ 2.9x doesn't allow static_cast<X const *>(void *)
       
   588 // apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
       
   589 
       
   590 template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
       
   591 {
       
   592     void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
       
   593     return const_cast<D *>(static_cast<D const *>(q));
       
   594 }
       
   595 
       
   596 #else
       
   597 
       
   598 template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
       
   599 {
       
   600     return static_cast<D *>(p._internal_get_deleter(BOOST_SP_TYPEID(D)));
       
   601 }
       
   602 
       
   603 #endif
       
   604 
       
   605 // atomic access
       
   606 
       
   607 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
       
   608 
       
   609 template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ )
       
   610 {
       
   611     return false;
       
   612 }
       
   613 
       
   614 template<class T> shared_ptr<T> atomic_load( shared_ptr<T> const * p )
       
   615 {
       
   616     boost::detail::spinlock_pool<2>::scoped_lock lock( p );
       
   617     return *p;
       
   618 }
       
   619 
       
   620 template<class T> inline shared_ptr<T> atomic_load_explicit( shared_ptr<T> const * p, memory_order /*mo*/ )
       
   621 {
       
   622     return atomic_load( p );
       
   623 }
       
   624 
       
   625 template<class T> void atomic_store( shared_ptr<T> * p, shared_ptr<T> r )
       
   626 {
       
   627     boost::detail::spinlock_pool<2>::scoped_lock lock( p );
       
   628     p->swap( r );
       
   629 }
       
   630 
       
   631 template<class T> inline void atomic_store_explicit( shared_ptr<T> * p, shared_ptr<T> r, memory_order /*mo*/ )
       
   632 {
       
   633     atomic_store( p, r ); // std::move( r )
       
   634 }
       
   635 
       
   636 template<class T> shared_ptr<T> atomic_exchange( shared_ptr<T> * p, shared_ptr<T> r )
       
   637 {
       
   638     boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
       
   639 
       
   640     sp.lock();
       
   641     p->swap( r );
       
   642     sp.unlock();
       
   643 
       
   644     return r; // return std::move( r )
       
   645 }
       
   646 
       
   647 template<class T> shared_ptr<T> atomic_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> r, memory_order /*mo*/ )
       
   648 {
       
   649     return atomic_exchange( p, r ); // std::move( r )
       
   650 }
       
   651 
       
   652 template<class T> bool atomic_compare_exchange( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w )
       
   653 {
       
   654     boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
       
   655 
       
   656     sp.lock();
       
   657 
       
   658     if( p->_internal_equiv( *v ) )
       
   659     {
       
   660         p->swap( w );
       
   661 
       
   662         sp.unlock();
       
   663 
       
   664         return true;
       
   665     }
       
   666     else
       
   667     {
       
   668         shared_ptr<T> tmp( *p );
       
   669 
       
   670         sp.unlock();
       
   671 
       
   672         tmp.swap( *v );
       
   673         return false;
       
   674     }
       
   675 }
       
   676 
       
   677 template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w, memory_order /*success*/, memory_order /*failure*/ )
       
   678 {
       
   679     return atomic_compare_exchange( p, v, w ); // std::move( w )
       
   680 }
       
   681 
       
   682 #endif
       
   683 
       
   684 } // namespace boost
       
   685 
       
   686 #ifdef BOOST_MSVC
       
   687 # pragma warning(pop)
       
   688 #endif
       
   689 
       
   690 #endif  // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
       
   691 
       
   692 #endif  // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED