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/detail/sp_typeinfo.hpp>
31 inline void atomic_increment( int * pw )
44 "=&r"( tmp ), "=m"( *pw ):
49 inline int atomic_decrement( int * pw )
59 "addiu %0, %1, -1\n\t"
63 "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
71 inline int atomic_conditional_increment( int * pw )
73 // if( *pw != 0 ) ++*pw;
88 "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
100 sp_counted_base( sp_counted_base const & );
101 sp_counted_base & operator= ( sp_counted_base const & );
103 int use_count_; // #shared
104 int weak_count_; // #weak + (#shared != 0)
108 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
112 virtual ~sp_counted_base() // nothrow
116 // dispose() is called when use_count_ drops to zero, to release
117 // the resources managed by *this.
119 virtual void dispose() = 0; // nothrow
121 // destroy() is called when weak_count_ drops to zero.
123 virtual void destroy() // nothrow
128 virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
132 atomic_increment( &use_count_ );
135 bool add_ref_lock() // true on success
137 return atomic_conditional_increment( &use_count_ ) != 0;
140 void release() // nothrow
142 if( atomic_decrement( &use_count_ ) == 0 )
149 void weak_add_ref() // nothrow
151 atomic_increment( &weak_count_ );
154 void weak_release() // nothrow
156 if( atomic_decrement( &weak_count_ ) == 0 )
162 long use_count() const // nothrow
164 return static_cast<int const volatile &>( use_count_ );
168 } // namespace detail
172 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED