File indexing completed on 2025-01-18 09:51:42
0001 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_X86_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_X86_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <boost/smart_ptr/detail/sp_obsolete.hpp>
0017
0018 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0019
0020 #include <boost/config/pragma_message.hpp>
0021 BOOST_PRAGMA_MESSAGE("Using g++/x86 atomic_count")
0022
0023 #endif
0024
0025 BOOST_SP_OBSOLETE()
0026
0027 namespace boost
0028 {
0029
0030 namespace detail
0031 {
0032
0033 class atomic_count
0034 {
0035 public:
0036
0037 explicit atomic_count( long v ) : value_( static_cast< int >( v ) ) {}
0038
0039 long operator++()
0040 {
0041 return atomic_exchange_and_add( &value_, +1 ) + 1;
0042 }
0043
0044 long operator--()
0045 {
0046 return atomic_exchange_and_add( &value_, -1 ) - 1;
0047 }
0048
0049 operator long() const
0050 {
0051 return atomic_exchange_and_add( &value_, 0 );
0052 }
0053
0054 private:
0055
0056 atomic_count(atomic_count const &);
0057 atomic_count & operator=(atomic_count const &);
0058
0059 mutable int value_;
0060
0061 private:
0062
0063 static int atomic_exchange_and_add( int * pw, int dv )
0064 {
0065
0066
0067
0068
0069 int r;
0070
0071 __asm__ __volatile__
0072 (
0073 "lock\n\t"
0074 "xadd %1, %0":
0075 "+m"( *pw ), "=r"( r ):
0076 "1"( dv ):
0077 "memory", "cc"
0078 );
0079
0080 return r;
0081 }
0082 };
0083
0084 }
0085
0086 }
0087
0088 #endif