[857] | 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 | #include <bits/atomicity.h>
|
---|
| 21 |
|
---|
| 22 | namespace boost
|
---|
| 23 | {
|
---|
| 24 |
|
---|
| 25 | namespace detail
|
---|
| 26 | {
|
---|
| 27 |
|
---|
| 28 | #if defined(__GLIBCXX__) // g++ 3.4+
|
---|
| 29 |
|
---|
| 30 | using __gnu_cxx::__atomic_add;
|
---|
| 31 | using __gnu_cxx::__exchange_and_add;
|
---|
| 32 |
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | class atomic_count
|
---|
| 36 | {
|
---|
| 37 | public:
|
---|
| 38 |
|
---|
| 39 | explicit atomic_count(long v) : value_(v) {}
|
---|
| 40 |
|
---|
| 41 | void operator++()
|
---|
| 42 | {
|
---|
| 43 | __atomic_add(&value_, 1);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | long operator--()
|
---|
| 47 | {
|
---|
| 48 | return __exchange_and_add(&value_, -1) - 1;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | operator long() const
|
---|
| 52 | {
|
---|
| 53 | return __exchange_and_add(&value_, 0);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | private:
|
---|
| 57 |
|
---|
| 58 | atomic_count(atomic_count const &);
|
---|
| 59 | atomic_count & operator=(atomic_count const &);
|
---|
| 60 |
|
---|
| 61 | mutable _Atomic_word value_;
|
---|
| 62 | };
|
---|
| 63 |
|
---|
| 64 | } // namespace detail
|
---|
| 65 |
|
---|
| 66 | } // namespace boost
|
---|
| 67 |
|
---|
| 68 | #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
|
---|