1 #ifndef BOOST_DETAIL_SP_COUNTED_BASE_CW_X86_HPP_INCLUDED
2 #define BOOST_DETAIL_SP_COUNTED_BASE_CW_X86_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // detail/sp_counted_base_cw_x86.hpp - CodeWarrion on 486+
13 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14 // Copyright 2004-2005 Peter Dimov
15 // Copyright 2005 Rene Rivera
17 // Distributed under the Boost Software License, Version 1.0. (See
18 // accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
22 // Lock-free algorithm by Alexander Terekhov
24 // Thanks to Ben Hitchings for the #weak + (#shared != 0)
36 inline int atomic_exchange_and_add( int * pw, int dv )
46 lock xadd dword ptr [esi], eax
50 inline void atomic_increment( int * pw )
52 //atomic_exchange_and_add( pw, 1 );
57 lock inc dword ptr [esi]
61 inline int atomic_conditional_increment( int * pw )
64 // if( rv != 0 ) ++*pw;
70 mov eax, dword ptr [esi]
76 lock cmpxchg dword ptr [esi], ebx
86 sp_counted_base( sp_counted_base const & );
87 sp_counted_base & operator= ( sp_counted_base const & );
89 int use_count_; // #shared
90 int weak_count_; // #weak + (#shared != 0)
94 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
98 virtual ~sp_counted_base() // nothrow
102 // dispose() is called when use_count_ drops to zero, to release
103 // the resources managed by *this.
105 virtual void dispose() = 0; // nothrow
107 // destroy() is called when weak_count_ drops to zero.
109 virtual void destroy() // nothrow
114 virtual void * get_deleter( std::type_info const & ti ) = 0;
118 atomic_increment( &use_count_ );
121 bool add_ref_lock() // true on success
123 return atomic_conditional_increment( &use_count_ ) != 0;
126 void release() // nothrow
128 if( atomic_exchange_and_add( &use_count_, -1 ) == 1 )
135 void weak_add_ref() // nothrow
137 atomic_increment( &weak_count_ );
140 void weak_release() // nothrow
142 if( atomic_exchange_and_add( &weak_count_, -1 ) == 1 )
148 long use_count() const // nothrow
150 return static_cast<int const volatile &>( use_count_ );
154 } // namespace detail
158 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_X86_HPP_INCLUDED