| 1 | #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_STD_ATOMIC_HPP_INCLUDED |
| 2 | #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_STD_ATOMIC_HPP_INCLUDED |
| 3 | |
| 4 | // |
| 5 | // boost/detail/atomic_count_std_atomic.hpp |
| 6 | // |
| 7 | // atomic_count for std::atomic |
| 8 | // |
| 9 | // Copyright 2013 Peter Dimov |
| 10 | // |
| 11 | // Distributed under the Boost Software License, Version 1.0. |
| 12 | // See accompanying file LICENSE_1_0.txt or copy at |
| 13 | // http://www.boost.org/LICENSE_1_0.txt |
| 14 | // |
| 15 | |
| 16 | #include <atomic> |
| 17 | #include <cstdint> |
| 18 | |
| 19 | namespace boost |
| 20 | { |
| 21 | |
| 22 | namespace detail |
| 23 | { |
| 24 | |
| 25 | class atomic_count |
| 26 | { |
| 27 | public: |
| 28 | |
| 29 | explicit atomic_count( long v ): value_( v ) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | long operator++() |
| 34 | { |
| 35 | return value_.fetch_add( i: 1, m: std::memory_order_acq_rel ) + 1; |
| 36 | } |
| 37 | |
| 38 | long operator--() |
| 39 | { |
| 40 | return value_.fetch_sub( i: 1, m: std::memory_order_acq_rel ) - 1; |
| 41 | } |
| 42 | |
| 43 | operator long() const |
| 44 | { |
| 45 | return value_.load( m: std::memory_order_acquire ); |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | |
| 50 | atomic_count(atomic_count const &); |
| 51 | atomic_count & operator=(atomic_count const &); |
| 52 | |
| 53 | std::atomic_int_least32_t value_; |
| 54 | }; |
| 55 | |
| 56 | } // namespace detail |
| 57 | |
| 58 | } // namespace boost |
| 59 | |
| 60 | #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_STD_ATOMIC_HPP_INCLUDED |
| 61 | |