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/smart_ptr/detail/sp_obsolete.hpp>
25 #include <boost/config.hpp>
27 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
29 #include <boost/config/pragma_message.hpp>
30 BOOST_PRAGMA_MESSAGE("Using g++/MIPS sp_counted_base")
42 inline void atomic_increment( int * pw )
52 #if !defined(__mips_isa_rev) || (__mips_isa_rev < 6)
60 "=&r"( tmp ), "=m"( *pw ):
65 inline int atomic_decrement( int * pw )
75 #if !defined(__mips_isa_rev) || (__mips_isa_rev < 6)
79 "addiu %0, %1, -1\n\t"
84 "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
92 inline int atomic_conditional_increment( int * pw )
94 // if( *pw != 0 ) ++*pw;
103 #if !defined(__mips_isa_rev) || (__mips_isa_rev < 6)
108 "addiu %1, %0, 1\n\t"
112 "addiu %0, %0, 1\n\t"
114 "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
122 class BOOST_SYMBOL_VISIBLE sp_counted_base
126 sp_counted_base( sp_counted_base const & );
127 sp_counted_base & operator= ( sp_counted_base const & );
129 int use_count_; // #shared
130 int weak_count_; // #weak + (#shared != 0)
134 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
138 virtual ~sp_counted_base() // nothrow
142 // dispose() is called when use_count_ drops to zero, to release
143 // the resources managed by *this.
145 virtual void dispose() = 0; // nothrow
147 // destroy() is called when weak_count_ drops to zero.
149 virtual void destroy() // nothrow
154 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
155 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
156 virtual void * get_untyped_deleter() = 0;
160 atomic_increment( &use_count_ );
163 bool add_ref_lock() // true on success
165 return atomic_conditional_increment( &use_count_ ) != 0;
168 void release() // nothrow
170 if( atomic_decrement( &use_count_ ) == 0 )
177 void weak_add_ref() // nothrow
179 atomic_increment( &weak_count_ );
182 void weak_release() // nothrow
184 if( atomic_decrement( &weak_count_ ) == 0 )
190 long use_count() const // nothrow
192 return static_cast<int const volatile &>( use_count_ );
196 } // namespace detail
200 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED