• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
17 
18 #include <boost/config/pragma_message.hpp>
19 BOOST_PRAGMA_MESSAGE("Using spinlock-based atomic_count")
20 
21 #endif
22 
23 namespace boost
24 {
25 
26 namespace detail
27 {
28 
29 class atomic_count
30 {
31 private:
32 
33 public:
34 
atomic_count(long v)35     explicit atomic_count( long v ): value_( v )
36     {
37     }
38 
operator ++()39     long operator++()
40     {
41         spinlock_pool<0>::scoped_lock lock( &value_ );
42         return ++value_;
43     }
44 
operator --()45     long operator--()
46     {
47         spinlock_pool<0>::scoped_lock lock( &value_ );
48         return --value_;
49     }
50 
operator long() const51     operator long() const
52     {
53         spinlock_pool<0>::scoped_lock lock( &value_ );
54         return value_;
55     }
56 
57 private:
58 
59     atomic_count(atomic_count const &);
60     atomic_count & operator=(atomic_count const &);
61 
62     long value_;
63 };
64 
65 } // namespace detail
66 
67 } // namespace boost
68 
69 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SPIN_HPP_INCLUDED
70