• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_ATOMIC_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_ATOMIC_HPP_INCLUDED
3 
4 // boost/detail/atomic_count_gcc_atomic.hpp
5 //
6 // atomic_count for g++ 4.7+
7 //
8 // Copyright 2007, 2020 Peter Dimov
9 //
10 // Distributed under the Boost Software License, Version 1.0.
11 // https://www.boost.org/LICENSE_1_0.txt
12 
13 #include <boost/cstdint.hpp>
14 
15 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
16 
17 #include <boost/config/pragma_message.hpp>
18 BOOST_PRAGMA_MESSAGE("Using __atomic atomic_count")
19 
20 #endif
21 
22 namespace boost
23 {
24 
25 namespace detail
26 {
27 
28 class atomic_count
29 {
30 public:
31 
atomic_count(long v)32     explicit atomic_count( long v ): value_( static_cast< boost::int_least32_t >( v ) )
33     {
34     }
35 
operator ++()36     long operator++()
37     {
38         return __atomic_add_fetch( &value_, +1, __ATOMIC_ACQ_REL );
39     }
40 
operator --()41     long operator--()
42     {
43         return __atomic_add_fetch( &value_, -1, __ATOMIC_ACQ_REL );
44     }
45 
operator long() const46     operator long() const
47     {
48         return __atomic_load_n( &value_, __ATOMIC_ACQUIRE );
49     }
50 
51 private:
52 
53     atomic_count(atomic_count const &);
54     atomic_count & operator=(atomic_count const &);
55 
56     boost::int_least32_t value_;
57 };
58 
59 } // namespace detail
60 
61 } // namespace boost
62 
63 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_ATOMIC_HPP_INCLUDED
64