]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/atomic_count_gcc.hpp
64-bit fix to boost::format.
[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 //  Permission to copy, use, modify, sell and distribute this software
15 //  is granted provided this copyright notice appears in all copies.
16 //  This software is provided "as is" without express or implied
17 //  warranty, and with no claim as to its suitability for any purpose.
18 //
19
20 #include <bits/atomicity.h>
21
22 namespace boost
23 {
24
25 namespace detail
26 {
27
28 class atomic_count
29 {
30 public:
31
32     explicit atomic_count(long v) : value_(v) {}
33
34     void operator++()
35     {
36         __atomic_add(&value_, 1);
37     }
38
39     long operator--()
40     {
41         return !__exchange_and_add(&value_, -1);
42     }
43
44     operator long() const
45     {
46         return __exchange_and_add(&value_, 0);
47     }
48
49 private:
50
51     atomic_count(atomic_count const &);
52     atomic_count & operator=(atomic_count const &);
53
54     _Atomic_word value_;
55 };
56
57 } // namespace detail
58
59 } // namespace boost
60
61 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED