1 #ifndef BOOST_DETAIL_SP_COUNTED_BASE_CW_PPC_HPP_INCLUDED
2 #define BOOST_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/detail/sp_typeinfo.hpp>
35 inline void atomic_increment( register long * pw )
50 inline long atomic_decrement( register long * pw )
71 inline long atomic_conditional_increment( register long * pw )
98 sp_counted_base( sp_counted_base const & );
99 sp_counted_base & operator= ( sp_counted_base const & );
101 long use_count_; // #shared
102 long weak_count_; // #weak + (#shared != 0)
106 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
110 virtual ~sp_counted_base() // nothrow
114 // dispose() is called when use_count_ drops to zero, to release
115 // the resources managed by *this.
117 virtual void dispose() = 0; // nothrow
119 // destroy() is called when weak_count_ drops to zero.
121 virtual void destroy() // nothrow
126 virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
130 atomic_increment( &use_count_ );
133 bool add_ref_lock() // true on success
135 return atomic_conditional_increment( &use_count_ ) != 0;
138 void release() // nothrow
140 if( atomic_decrement( &use_count_ ) == 0 )
147 void weak_add_ref() // nothrow
149 atomic_increment( &weak_count_ );
152 void weak_release() // nothrow
154 if( atomic_decrement( &weak_count_ ) == 0 )
160 long use_count() const // nothrow
162 return static_cast<long const volatile &>( use_count_ );
166 } // namespace detail
170 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_CW_PPC_HPP_INCLUDED