1 #ifndef BOOST_DETAIL_SP_COUNTED_BASE_SOLARIS_HPP_INCLUDED
2 #define BOOST_DETAIL_SP_COUNTED_BASE_SOLARIS_HPP_INCLUDED
5 // detail/sp_counted_base_solaris.hpp
6 // based on: detail/sp_counted_base_w32.hpp
8 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
9 // Copyright 2004-2005 Peter Dimov
10 // Copyright 2006 Michael van der Westhuizen
12 // Distributed under the Boost Software License, Version 1.0. (See
13 // accompanying file LICENSE_1_0.txt or copy at
14 // http://www.boost.org/LICENSE_1_0.txt)
17 // Lock-free algorithm by Alexander Terekhov
19 // Thanks to Ben Hitchings for the #weak + (#shared != 0)
23 #include <boost/detail/sp_typeinfo.hpp>
36 sp_counted_base( sp_counted_base const & );
37 sp_counted_base & operator= ( sp_counted_base const & );
39 uint32_t use_count_; // #shared
40 uint32_t weak_count_; // #weak + (#shared != 0)
44 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
48 virtual ~sp_counted_base() // nothrow
52 // dispose() is called when use_count_ drops to zero, to release
53 // the resources managed by *this.
55 virtual void dispose() = 0; // nothrow
57 // destroy() is called when weak_count_ drops to zero.
59 virtual void destroy() // nothrow
64 virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
68 atomic_inc_32( &use_count_ );
71 bool add_ref_lock() // true on success
75 uint32_t tmp = static_cast< uint32_t const volatile& >( use_count_ );
76 if( tmp == 0 ) return false;
77 if( atomic_cas_32( &use_count_, tmp, tmp + 1 ) == tmp ) return true;
81 void release() // nothrow
83 if( atomic_dec_32_nv( &use_count_ ) == 0 )
90 void weak_add_ref() // nothrow
92 atomic_inc_32( &weak_count_ );
95 void weak_release() // nothrow
97 if( atomic_dec_32_nv( &weak_count_ ) == 0 )
103 long use_count() const // nothrow
105 return static_cast<long const volatile &>( use_count_ );
109 } // namespace detail
113 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_SOLARIS_HPP_INCLUDED