]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/smart_ptr/detail/atomic_count_gcc.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / smart_ptr / detail / atomic_count_gcc.hpp
CommitLineData
7c673cae
FG
1#ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
2#define BOOST_SMART_PTR_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.
b32b8144 12// Copyright (c) 2002 Lars Gullik Bjønnes <larsbj@lyx.org>
7c673cae
FG
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__ * 100 + __GNUC_MINOR__ >= 402
21# include <ext/atomicity.h>
22#else
23# include <bits/atomicity.h>
24#endif
25
20effc67
TL
26#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
27
28#include <boost/config/pragma_message.hpp>
29BOOST_PRAGMA_MESSAGE("Using libstdc++ atomic_count")
30
31#endif
32
7c673cae
FG
33namespace boost
34{
35
36namespace detail
37{
38
39#if defined(__GLIBCXX__) // g++ 3.4+
40
41using __gnu_cxx::__atomic_add;
42using __gnu_cxx::__exchange_and_add;
43
44#endif
45
46class atomic_count
47{
48public:
49
50 explicit atomic_count( long v ) : value_( v ) {}
51
52 long operator++()
53 {
54 return __exchange_and_add( &value_, +1 ) + 1;
55 }
56
57 long operator--()
58 {
59 return __exchange_and_add( &value_, -1 ) - 1;
60 }
61
62 operator long() const
63 {
64 return __exchange_and_add( &value_, 0 );
65 }
66
67private:
68
69 atomic_count(atomic_count const &);
70 atomic_count & operator=(atomic_count const &);
71
72 mutable _Atomic_word value_;
73};
74
75} // namespace detail
76
77} // namespace boost
78
79#endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED