]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/atomic_count_sync.hpp
boost: update to 1.42.0
[lyx.git] / boost / boost / detail / atomic_count_sync.hpp
1 #ifndef BOOST_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED
2 #define BOOST_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED
3
4 //
5 //  boost/detail/atomic_count_sync.hpp
6 //
7 //  atomic_count for g++ 4.1+
8 //
9 //  http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
10 //
11 //  Copyright 2007 Peter Dimov
12 //
13 //  Distributed under the Boost Software License, Version 1.0. (See
14 //  accompanying file LICENSE_1_0.txt or copy at
15 //  http://www.boost.org/LICENSE_1_0.txt)
16 //
17
18 namespace boost
19 {
20
21 namespace detail
22 {
23
24 class atomic_count
25 {
26 public:
27
28     explicit atomic_count( long v ) : value_( v ) {}
29
30     void operator++()
31     {
32         __sync_add_and_fetch( &value_, 1 );
33     }
34
35     long operator--()
36     {
37         return __sync_add_and_fetch( &value_, -1 );
38     }
39
40     operator long() const
41     {
42         return __sync_fetch_and_add( &value_, 0 );
43     }
44
45 private:
46
47     atomic_count(atomic_count const &);
48     atomic_count & operator=(atomic_count const &);
49
50     mutable long value_;
51 };
52
53 } // namespace detail
54
55 } // namespace boost
56
57 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED