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/smart_ptr/detail/sp_obsolete.hpp>
29 #include <boost/config.hpp>
31 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
33 #include <boost/config/pragma_message.hpp>
34 BOOST_PRAGMA_MESSAGE("Using CodeWarrior/PowerPC sp_counted_base")
46 inline void atomic_increment( register long * pw )
61 inline long atomic_decrement( register long * pw )
82 inline long atomic_conditional_increment( register long * pw )
105 class BOOST_SYMBOL_VISIBLE sp_counted_base
109 sp_counted_base( sp_counted_base const & );
110 sp_counted_base & operator= ( sp_counted_base const & );
112 long use_count_; // #shared
113 long weak_count_; // #weak + (#shared != 0)
117 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
121 virtual ~sp_counted_base() // nothrow
125 // dispose() is called when use_count_ drops to zero, to release
126 // the resources managed by *this.
128 virtual void dispose() = 0; // nothrow
130 // destroy() is called when weak_count_ drops to zero.
132 virtual void destroy() // nothrow
137 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
138 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
139 virtual void * get_untyped_deleter() = 0;
143 atomic_increment( &use_count_ );
146 bool add_ref_lock() // true on success
148 return atomic_conditional_increment( &use_count_ ) != 0;
151 void release() // nothrow
153 if( atomic_decrement( &use_count_ ) == 0 )
160 void weak_add_ref() // nothrow
162 atomic_increment( &weak_count_ );
165 void weak_release() // nothrow
167 if( atomic_decrement( &weak_count_ ) == 0 )
173 long use_count() const // nothrow
175 return static_cast<long const volatile &>( use_count_ );
179 } // namespace detail
183 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CW_PPC_HPP_INCLUDED