1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_PPC_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_PPC_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // detail/sp_counted_base_gcc_ppc.hpp - g++ on PowerPC
13 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14 // Copyright 2004-2005 Peter Dimov
16 // Distributed under the Boost Software License, Version 1.0. (See
17 // accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
21 // Lock-free algorithm by Alexander Terekhov
23 // Thanks to Ben Hitchings for the #weak + (#shared != 0)
27 #include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
28 #include <boost/config.hpp>
36 inline void atomic_increment( int * pw )
47 "stwcx. %1, 0, %2\n\t"
50 "=m"( *pw ), "=&b"( tmp ):
51 "r"( pw ), "m"( *pw ):
56 inline int atomic_decrement( int * pw )
68 "stwcx. %1, 0, %2\n\t"
72 "=m"( *pw ), "=&b"( rv ):
73 "r"( pw ), "m"( *pw ):
80 inline int atomic_conditional_increment( int * pw )
82 // if( *pw != 0 ) ++*pw;
95 "stwcx. %1, 0, %2\n\t"
98 "=m"( *pw ), "=&b"( rv ):
99 "r"( pw ), "m"( *pw ):
106 class BOOST_SYMBOL_VISIBLE sp_counted_base
110 sp_counted_base( sp_counted_base const & );
111 sp_counted_base & operator= ( sp_counted_base const & );
113 int use_count_; // #shared
114 int weak_count_; // #weak + (#shared != 0)
118 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
122 virtual ~sp_counted_base() // nothrow
126 // dispose() is called when use_count_ drops to zero, to release
127 // the resources managed by *this.
129 virtual void dispose() = 0; // nothrow
131 // destroy() is called when weak_count_ drops to zero.
133 virtual void destroy() // nothrow
138 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
139 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
140 virtual void * get_untyped_deleter() = 0;
144 atomic_increment( &use_count_ );
147 bool add_ref_lock() // true on success
149 return atomic_conditional_increment( &use_count_ ) != 0;
152 void release() // nothrow
154 if( atomic_decrement( &use_count_ ) == 0 )
161 void weak_add_ref() // nothrow
163 atomic_increment( &weak_count_ );
166 void weak_release() // nothrow
168 if( atomic_decrement( &weak_count_ ) == 0 )
174 long use_count() const // nothrow
176 return static_cast<int const volatile &>( use_count_ );
180 } // namespace detail
184 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_PPC_HPP_INCLUDED