1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CW_PPC_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CW_PPC_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // detail/sp_counted_base_cw_ppc.hpp - CodeWarrior 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( register long * pw )
51 inline long atomic_decrement( register long * pw )
72 inline long atomic_conditional_increment( register long * pw )
95 class BOOST_SYMBOL_VISIBLE sp_counted_base
99 sp_counted_base( sp_counted_base const & );
100 sp_counted_base & operator= ( sp_counted_base const & );
102 long use_count_; // #shared
103 long weak_count_; // #weak + (#shared != 0)
107 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
111 virtual ~sp_counted_base() // nothrow
115 // dispose() is called when use_count_ drops to zero, to release
116 // the resources managed by *this.
118 virtual void dispose() = 0; // nothrow
120 // destroy() is called when weak_count_ drops to zero.
122 virtual void destroy() // nothrow
127 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
128 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
129 virtual void * get_untyped_deleter() = 0;
133 atomic_increment( &use_count_ );
136 bool add_ref_lock() // true on success
138 return atomic_conditional_increment( &use_count_ ) != 0;
141 void release() // nothrow
143 if( atomic_decrement( &use_count_ ) == 0 )
150 void weak_add_ref() // nothrow
152 atomic_increment( &weak_count_ );
155 void weak_release() // nothrow
157 if( atomic_decrement( &weak_count_ ) == 0 )
163 long use_count() const // nothrow
165 return static_cast<long const volatile &>( use_count_ );
169 } // namespace detail
173 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CW_PPC_HPP_INCLUDED