File indexing completed on 2025-01-18 09:51:42
0001 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_STD_ATOMIC_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_STD_ATOMIC_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <atomic>
0017 #include <cstdint>
0018
0019 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0020
0021 #include <boost/config/pragma_message.hpp>
0022 BOOST_PRAGMA_MESSAGE("Using std::atomic atomic_count")
0023
0024 #endif
0025
0026 namespace boost
0027 {
0028
0029 namespace detail
0030 {
0031
0032 class atomic_count
0033 {
0034 public:
0035
0036 explicit atomic_count( long v ): value_( static_cast< std::int_least32_t >( v ) )
0037 {
0038 }
0039
0040 long operator++()
0041 {
0042 return value_.fetch_add( 1, std::memory_order_acq_rel ) + 1;
0043 }
0044
0045 long operator--()
0046 {
0047 return value_.fetch_sub( 1, std::memory_order_acq_rel ) - 1;
0048 }
0049
0050 operator long() const
0051 {
0052 return value_.load( std::memory_order_acquire );
0053 }
0054
0055 private:
0056
0057 atomic_count(atomic_count const &);
0058 atomic_count & operator=(atomic_count const &);
0059
0060 std::atomic_int_least32_t value_;
0061 };
0062
0063 }
0064
0065 }
0066
0067 #endif