]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/atomic/atomic.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / atomic / atomic.hpp
CommitLineData
7c673cae
FG
1/*
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * Copyright (c) 2011 Helge Bahmann
7 * Copyright (c) 2013 Tim Blechmann
20effc67 8 * Copyright (c) 2014, 2020 Andrey Semashev
7c673cae
FG
9 */
10/*!
11 * \file atomic/atomic.hpp
12 *
20effc67 13 * This header contains definition of \c atomic template.
7c673cae
FG
14 */
15
16#ifndef BOOST_ATOMIC_ATOMIC_HPP_INCLUDED_
17#define BOOST_ATOMIC_ATOMIC_HPP_INCLUDED_
18
20effc67
TL
19#include <cstddef>
20#include <boost/cstdint.hpp>
21#include <boost/static_assert.hpp>
22#include <boost/memory_order.hpp>
7c673cae 23#include <boost/atomic/capabilities.hpp>
20effc67
TL
24#include <boost/atomic/detail/config.hpp>
25#include <boost/atomic/detail/classify.hpp>
26#include <boost/atomic/detail/atomic_impl.hpp>
27#include <boost/atomic/detail/type_traits/is_trivially_copyable.hpp>
28#include <boost/atomic/detail/header.hpp>
7c673cae
FG
29
30#ifdef BOOST_HAS_PRAGMA_ONCE
31#pragma once
32#endif
33
34namespace boost {
20effc67
TL
35namespace atomics {
36
37//! Atomic object
38template< typename T >
39class atomic :
40 public atomics::detail::base_atomic< T, typename atomics::detail::classify< T >::type, false >
41{
42private:
43 typedef atomics::detail::base_atomic< T, typename atomics::detail::classify< T >::type, false > base_type;
44 typedef typename base_type::value_arg_type value_arg_type;
45
46public:
47 typedef typename base_type::value_type value_type;
48 // Deprecated, use value_type instead
49 BOOST_ATOMIC_DETAIL_STORAGE_DEPRECATED
50 typedef typename base_type::storage_type storage_type;
51
52 BOOST_STATIC_ASSERT_MSG(sizeof(value_type) > 0u, "boost::atomic<T> requires T to be a complete type");
53#if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_IS_TRIVIALLY_COPYABLE)
54 BOOST_STATIC_ASSERT_MSG(atomics::detail::is_trivially_copyable< value_type >::value, "boost::atomic<T> requires T to be a trivially copyable type");
55#endif
56
57public:
58 BOOST_DEFAULTED_FUNCTION(atomic() BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_DECL, BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_IMPL {})
59 BOOST_FORCEINLINE BOOST_ATOMIC_DETAIL_CONSTEXPR_UNION_INIT atomic(value_arg_type v) BOOST_NOEXCEPT : base_type(v) {}
60
61 BOOST_FORCEINLINE value_type operator= (value_arg_type v) BOOST_NOEXCEPT
62 {
63 this->store(v);
64 return v;
65 }
66
67 BOOST_FORCEINLINE value_type operator= (value_arg_type v) volatile BOOST_NOEXCEPT
68 {
69 this->store(v);
70 return v;
71 }
72
73 BOOST_FORCEINLINE operator value_type() const volatile BOOST_NOEXCEPT
74 {
75 return this->load();
76 }
77
78 // Deprecated, use value() instead
79 BOOST_ATOMIC_DETAIL_STORAGE_DEPRECATED
80 BOOST_FORCEINLINE typename base_type::storage_type& storage() BOOST_NOEXCEPT { return base_type::storage(); }
81 BOOST_ATOMIC_DETAIL_STORAGE_DEPRECATED
82 BOOST_FORCEINLINE typename base_type::storage_type volatile& storage() volatile BOOST_NOEXCEPT { return base_type::storage(); }
83 BOOST_ATOMIC_DETAIL_STORAGE_DEPRECATED
84 BOOST_FORCEINLINE typename base_type::storage_type const& storage() const BOOST_NOEXCEPT { return base_type::storage(); }
85 BOOST_ATOMIC_DETAIL_STORAGE_DEPRECATED
86 BOOST_FORCEINLINE typename base_type::storage_type const volatile& storage() const volatile BOOST_NOEXCEPT { return base_type::storage(); }
87
88 BOOST_DELETED_FUNCTION(atomic(atomic const&))
89 BOOST_DELETED_FUNCTION(atomic& operator= (atomic const&))
90 BOOST_DELETED_FUNCTION(atomic& operator= (atomic const&) volatile)
91};
92
93typedef atomic< char > atomic_char;
94typedef atomic< unsigned char > atomic_uchar;
95typedef atomic< signed char > atomic_schar;
96typedef atomic< uint8_t > atomic_uint8_t;
97typedef atomic< int8_t > atomic_int8_t;
98typedef atomic< unsigned short > atomic_ushort;
99typedef atomic< short > atomic_short;
100typedef atomic< uint16_t > atomic_uint16_t;
101typedef atomic< int16_t > atomic_int16_t;
102typedef atomic< unsigned int > atomic_uint;
103typedef atomic< int > atomic_int;
104typedef atomic< uint32_t > atomic_uint32_t;
105typedef atomic< int32_t > atomic_int32_t;
106typedef atomic< unsigned long > atomic_ulong;
107typedef atomic< long > atomic_long;
108typedef atomic< uint64_t > atomic_uint64_t;
109typedef atomic< int64_t > atomic_int64_t;
110#ifdef BOOST_HAS_LONG_LONG
111typedef atomic< boost::ulong_long_type > atomic_ullong;
112typedef atomic< boost::long_long_type > atomic_llong;
113#endif
114typedef atomic< void* > atomic_address;
115typedef atomic< bool > atomic_bool;
116typedef atomic< wchar_t > atomic_wchar_t;
117#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811
118typedef atomic< char8_t > atomic_char8_t;
119#endif
120#if !defined(BOOST_NO_CXX11_CHAR16_T)
121typedef atomic< char16_t > atomic_char16_t;
122#endif
123#if !defined(BOOST_NO_CXX11_CHAR32_T)
124typedef atomic< char32_t > atomic_char32_t;
125#endif
126
127typedef atomic< int_least8_t > atomic_int_least8_t;
128typedef atomic< uint_least8_t > atomic_uint_least8_t;
129typedef atomic< int_least16_t > atomic_int_least16_t;
130typedef atomic< uint_least16_t > atomic_uint_least16_t;
131typedef atomic< int_least32_t > atomic_int_least32_t;
132typedef atomic< uint_least32_t > atomic_uint_least32_t;
133typedef atomic< int_least64_t > atomic_int_least64_t;
134typedef atomic< uint_least64_t > atomic_uint_least64_t;
135typedef atomic< int_fast8_t > atomic_int_fast8_t;
136typedef atomic< uint_fast8_t > atomic_uint_fast8_t;
137typedef atomic< int_fast16_t > atomic_int_fast16_t;
138typedef atomic< uint_fast16_t > atomic_uint_fast16_t;
139typedef atomic< int_fast32_t > atomic_int_fast32_t;
140typedef atomic< uint_fast32_t > atomic_uint_fast32_t;
141typedef atomic< int_fast64_t > atomic_int_fast64_t;
142typedef atomic< uint_fast64_t > atomic_uint_fast64_t;
143typedef atomic< intmax_t > atomic_intmax_t;
144typedef atomic< uintmax_t > atomic_uintmax_t;
145
146#if !defined(BOOST_ATOMIC_NO_FLOATING_POINT)
147typedef atomic< float > atomic_float_t;
148typedef atomic< double > atomic_double_t;
149typedef atomic< long double > atomic_long_double_t;
150#endif
151
152typedef atomic< std::size_t > atomic_size_t;
153typedef atomic< std::ptrdiff_t > atomic_ptrdiff_t;
154
155#if defined(BOOST_HAS_INTPTR_T)
156typedef atomic< boost::intptr_t > atomic_intptr_t;
157typedef atomic< boost::uintptr_t > atomic_uintptr_t;
158#endif
159
160// Select the lock-free atomic types that has natively supported waiting/notifying operations.
161// Prefer 32-bit types the most as those have the best performance on current 32 and 64-bit architectures.
162#if BOOST_ATOMIC_INT32_LOCK_FREE == 2 && BOOST_ATOMIC_HAS_NATIVE_INT32_WAIT_NOTIFY == 2
163typedef atomic< uint32_t > atomic_unsigned_lock_free;
164typedef atomic< int32_t > atomic_signed_lock_free;
165#elif BOOST_ATOMIC_INT64_LOCK_FREE == 2 && BOOST_ATOMIC_HAS_NATIVE_INT64_WAIT_NOTIFY == 2
166typedef atomic< uint64_t > atomic_unsigned_lock_free;
167typedef atomic< int64_t > atomic_signed_lock_free;
168#elif BOOST_ATOMIC_INT16_LOCK_FREE == 2 && BOOST_ATOMIC_HAS_NATIVE_INT16_WAIT_NOTIFY == 2
169typedef atomic< uint16_t > atomic_unsigned_lock_free;
170typedef atomic< int16_t > atomic_signed_lock_free;
171#elif BOOST_ATOMIC_INT8_LOCK_FREE == 2 && BOOST_ATOMIC_HAS_NATIVE_INT8_WAIT_NOTIFY == 2
172typedef atomic< uint8_t > atomic_unsigned_lock_free;
173typedef atomic< int8_t > atomic_signed_lock_free;
174#elif BOOST_ATOMIC_INT32_LOCK_FREE == 2
175typedef atomic< uint32_t > atomic_unsigned_lock_free;
176typedef atomic< int32_t > atomic_signed_lock_free;
177#elif BOOST_ATOMIC_INT64_LOCK_FREE == 2
178typedef atomic< uint64_t > atomic_unsigned_lock_free;
179typedef atomic< int64_t > atomic_signed_lock_free;
180#elif BOOST_ATOMIC_INT16_LOCK_FREE == 2
181typedef atomic< uint16_t > atomic_unsigned_lock_free;
182typedef atomic< int16_t > atomic_signed_lock_free;
183#elif BOOST_ATOMIC_INT8_LOCK_FREE == 2
184typedef atomic< uint8_t > atomic_unsigned_lock_free;
185typedef atomic< int8_t > atomic_signed_lock_free;
186#else
187#define BOOST_ATOMIC_DETAIL_NO_LOCK_FREE_TYPEDEFS
188#endif
189
190} // namespace atomics
7c673cae
FG
191
192using atomics::atomic;
193
194using atomics::atomic_char;
195using atomics::atomic_uchar;
196using atomics::atomic_schar;
197using atomics::atomic_uint8_t;
198using atomics::atomic_int8_t;
199using atomics::atomic_ushort;
200using atomics::atomic_short;
201using atomics::atomic_uint16_t;
202using atomics::atomic_int16_t;
203using atomics::atomic_uint;
204using atomics::atomic_int;
205using atomics::atomic_uint32_t;
206using atomics::atomic_int32_t;
207using atomics::atomic_ulong;
208using atomics::atomic_long;
209using atomics::atomic_uint64_t;
210using atomics::atomic_int64_t;
211#ifdef BOOST_HAS_LONG_LONG
212using atomics::atomic_ullong;
213using atomics::atomic_llong;
214#endif
215using atomics::atomic_address;
216using atomics::atomic_bool;
217using atomics::atomic_wchar_t;
20effc67
TL
218#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811
219using atomics::atomic_char8_t;
220#endif
7c673cae
FG
221#if !defined(BOOST_NO_CXX11_CHAR16_T)
222using atomics::atomic_char16_t;
223#endif
224#if !defined(BOOST_NO_CXX11_CHAR32_T)
225using atomics::atomic_char32_t;
226#endif
227
228using atomics::atomic_int_least8_t;
229using atomics::atomic_uint_least8_t;
230using atomics::atomic_int_least16_t;
231using atomics::atomic_uint_least16_t;
232using atomics::atomic_int_least32_t;
233using atomics::atomic_uint_least32_t;
234using atomics::atomic_int_least64_t;
235using atomics::atomic_uint_least64_t;
236using atomics::atomic_int_fast8_t;
237using atomics::atomic_uint_fast8_t;
238using atomics::atomic_int_fast16_t;
239using atomics::atomic_uint_fast16_t;
240using atomics::atomic_int_fast32_t;
241using atomics::atomic_uint_fast32_t;
242using atomics::atomic_int_fast64_t;
243using atomics::atomic_uint_fast64_t;
244using atomics::atomic_intmax_t;
245using atomics::atomic_uintmax_t;
246
11fdf7f2
TL
247#if !defined(BOOST_ATOMIC_NO_FLOATING_POINT)
248using atomics::atomic_float_t;
249using atomics::atomic_double_t;
250using atomics::atomic_long_double_t;
251#endif
252
7c673cae
FG
253using atomics::atomic_size_t;
254using atomics::atomic_ptrdiff_t;
255
256#if defined(BOOST_HAS_INTPTR_T)
257using atomics::atomic_intptr_t;
258using atomics::atomic_uintptr_t;
259#endif
260
20effc67
TL
261#if !defined(BOOST_ATOMIC_DETAIL_NO_LOCK_FREE_TYPEDEFS)
262using atomics::atomic_unsigned_lock_free;
263using atomics::atomic_signed_lock_free;
264#endif
265#undef BOOST_ATOMIC_DETAIL_NO_LOCK_FREE_TYPEDEFS
266
7c673cae
FG
267} // namespace boost
268
20effc67
TL
269#include <boost/atomic/detail/footer.hpp>
270
7c673cae 271#endif // BOOST_ATOMIC_ATOMIC_HPP_INCLUDED_