File indexing completed on 2025-01-18 09:51:42
0001 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
0021 # include <ext/atomicity.h>
0022 #else
0023 # include <bits/atomicity.h>
0024 #endif
0025
0026 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0027
0028 #include <boost/config/pragma_message.hpp>
0029 BOOST_PRAGMA_MESSAGE("Using libstdc++ atomic_count")
0030
0031 #endif
0032
0033 namespace boost
0034 {
0035
0036 namespace detail
0037 {
0038
0039 #if defined(__GLIBCXX__)
0040
0041 using __gnu_cxx::__atomic_add;
0042 using __gnu_cxx::__exchange_and_add;
0043
0044 #endif
0045
0046 class atomic_count
0047 {
0048 public:
0049
0050 explicit atomic_count( long v ) : value_( v ) {}
0051
0052 long operator++()
0053 {
0054 return __exchange_and_add( &value_, +1 ) + 1;
0055 }
0056
0057 long operator--()
0058 {
0059 return __exchange_and_add( &value_, -1 ) - 1;
0060 }
0061
0062 operator long() const
0063 {
0064 return __exchange_and_add( &value_, 0 );
0065 }
0066
0067 private:
0068
0069 atomic_count(atomic_count const &);
0070 atomic_count & operator=(atomic_count const &);
0071
0072 mutable _Atomic_word value_;
0073 };
0074
0075 }
0076
0077 }
0078
0079 #endif