1 #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED
2 #define BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // detail/sp_counted_base_gcc_mips.hpp - g++ on MIPS
13 // Copyright (c) 2009, Spirent Communications, Inc.
15 // Distributed under the Boost Software License, Version 1.0. (See
16 // accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
20 // Lock-free algorithm by Alexander Terekhov
23 #include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
24 #include <boost/config.hpp>
32 inline void atomic_increment( int * pw )
42 #if !defined(__mips_isa_rev) || (__mips_isa_rev < 6)
50 "=&r"( tmp ), "=m"( *pw ):
55 inline int atomic_decrement( int * pw )
65 #if !defined(__mips_isa_rev) || (__mips_isa_rev < 6)
69 "addiu %0, %1, -1\n\t"
74 "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
82 inline int atomic_conditional_increment( int * pw )
84 // if( *pw != 0 ) ++*pw;
93 #if !defined(__mips_isa_rev) || (__mips_isa_rev < 6)
102 "addiu %0, %0, 1\n\t"
104 "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
112 class BOOST_SYMBOL_VISIBLE sp_counted_base
116 sp_counted_base( sp_counted_base const & );
117 sp_counted_base & operator= ( sp_counted_base const & );
119 int use_count_; // #shared
120 int weak_count_; // #weak + (#shared != 0)
124 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
128 virtual ~sp_counted_base() // nothrow
132 // dispose() is called when use_count_ drops to zero, to release
133 // the resources managed by *this.
135 virtual void dispose() = 0; // nothrow
137 // destroy() is called when weak_count_ drops to zero.
139 virtual void destroy() // nothrow
144 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
145 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
146 virtual void * get_untyped_deleter() = 0;
150 atomic_increment( &use_count_ );
153 bool add_ref_lock() // true on success
155 return atomic_conditional_increment( &use_count_ ) != 0;
158 void release() // nothrow
160 if( atomic_decrement( &use_count_ ) == 0 )
167 void weak_add_ref() // nothrow
169 atomic_increment( &weak_count_ );
172 void weak_release() // nothrow
174 if( atomic_decrement( &weak_count_ ) == 0 )
180 long use_count() const // nothrow
182 return static_cast<int const volatile &>( use_count_ );
186 } // namespace detail
190 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED