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