]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/atomic_count_gcc.hpp
update to boost 1.32.0
[lyx.git] / boost / boost / detail / atomic_count_gcc.hpp
1 #ifndef BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
2 #define BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
3
4 //
5 //  boost/detail/atomic_count_gcc.hpp
6 //
7 //  atomic_count for GNU libstdc++ v3
8 //
9 //  http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html
10 //
11 //  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
12 //  Copyright (c) 2002 Lars Gullik Bjønnes <larsbj@lyx.org>
13 //
14 //  Distributed under the Boost Software License, Version 1.0. (See
15 //  accompanying file LICENSE_1_0.txt or copy at
16 //  http://www.boost.org/LICENSE_1_0.txt)
17 //
18
19 #include <bits/atomicity.h>
20
21 namespace boost
22 {
23
24 namespace detail
25 {
26
27 class atomic_count
28 {
29 public:
30
31     explicit atomic_count(long v) : value_(v) {}
32
33     void operator++()
34     {
35         __atomic_add(&value_, 1);
36     }
37
38     long operator--()
39     {
40         return __exchange_and_add(&value_, -1) - 1;
41     }
42
43     operator long() const
44     {
45         return __exchange_and_add(&value_, 0);
46     }
47
48 private:
49
50     atomic_count(atomic_count const &);
51     atomic_count & operator=(atomic_count const &);
52
53     mutable _Atomic_word value_;
54 };
55
56 } // namespace detail
57
58 } // namespace boost
59
60 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED