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 | // Copyright 2003-2005 Peter Dimov |
---|
14 | // |
---|
15 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
16 | // accompanying file LICENSE_1_0.txt or copy at |
---|
17 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
18 | // |
---|
19 | |
---|
20 | #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) |
---|
21 | # include <ext/atomicity.h> |
---|
22 | #else |
---|
23 | # include <bits/atomicity.h> |
---|
24 | #endif |
---|
25 | |
---|
26 | namespace boost |
---|
27 | { |
---|
28 | |
---|
29 | namespace detail |
---|
30 | { |
---|
31 | |
---|
32 | #if defined(__GLIBCXX__) // g++ 3.4+ |
---|
33 | |
---|
34 | using __gnu_cxx::__atomic_add; |
---|
35 | using __gnu_cxx::__exchange_and_add; |
---|
36 | |
---|
37 | #endif |
---|
38 | |
---|
39 | class atomic_count |
---|
40 | { |
---|
41 | public: |
---|
42 | |
---|
43 | explicit atomic_count(long v) : value_(v) {} |
---|
44 | |
---|
45 | void operator++() |
---|
46 | { |
---|
47 | __atomic_add(&value_, 1); |
---|
48 | } |
---|
49 | |
---|
50 | long operator--() |
---|
51 | { |
---|
52 | return __exchange_and_add(&value_, -1) - 1; |
---|
53 | } |
---|
54 | |
---|
55 | operator long() const |
---|
56 | { |
---|
57 | return __exchange_and_add(&value_, 0); |
---|
58 | } |
---|
59 | |
---|
60 | private: |
---|
61 | |
---|
62 | atomic_count(atomic_count const &); |
---|
63 | atomic_count & operator=(atomic_count const &); |
---|
64 | |
---|
65 | mutable _Atomic_word value_; |
---|
66 | }; |
---|
67 | |
---|
68 | } // namespace detail |
---|
69 | |
---|
70 | } // namespace boost |
---|
71 | |
---|
72 | #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED |
---|