]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/detail/interlocked.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / detail / interlocked.hpp
1 #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
2 #define BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
3
4 //
5 // boost/detail/interlocked.hpp
6 //
7 // Copyright 2005 Peter Dimov
8 // Copyright 2018, 2019 Andrey Semashev
9 //
10 // Distributed under the Boost Software License, Version 1.0. (See
11 // accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13 //
14
15 #include <boost/config.hpp>
16
17 #ifdef BOOST_HAS_PRAGMA_ONCE
18 #pragma once
19 #endif
20
21 // BOOST_INTERLOCKED_HAS_INTRIN_H
22
23 // VC9 has intrin.h, but it collides with <utility>
24 #if defined( BOOST_MSVC ) && BOOST_MSVC >= 1600
25
26 # define BOOST_INTERLOCKED_HAS_INTRIN_H
27
28 // Unlike __MINGW64__, __MINGW64_VERSION_MAJOR is defined by MinGW-w64 for both 32 and 64-bit targets.
29 #elif defined( __MINGW64_VERSION_MAJOR )
30
31 // MinGW-w64 provides intrin.h for both 32 and 64-bit targets.
32 # define BOOST_INTERLOCKED_HAS_INTRIN_H
33
34 #elif defined( __CYGWIN__ )
35
36 // Cygwin and Cygwin64 provide intrin.h. On Cygwin64 we have to use intrin.h because it's an LP64 target,
37 // where long is 64-bit and therefore _Interlocked* functions have different signatures.
38 # define BOOST_INTERLOCKED_HAS_INTRIN_H
39
40 // Intel C++ on Windows on VC10+ stdlib
41 #elif defined( BOOST_INTEL_WIN ) && defined( _CPPLIB_VER ) && _CPPLIB_VER >= 520
42
43 # define BOOST_INTERLOCKED_HAS_INTRIN_H
44
45 // clang-cl on Windows on VC10+ stdlib
46 #elif defined( __clang__ ) && defined( _MSC_VER ) && defined( _CPPLIB_VER ) && _CPPLIB_VER >= 520
47
48 # define BOOST_INTERLOCKED_HAS_INTRIN_H
49
50 #endif
51
52 #if !defined(__LP64__)
53 #define BOOST_INTERLOCKED_LONG32 long
54 #else
55 #define BOOST_INTERLOCKED_LONG32 int
56 #endif
57
58 #if defined( BOOST_USE_WINDOWS_H )
59
60 # include <windows.h>
61
62 # define BOOST_INTERLOCKED_INCREMENT(dest) \
63 InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
64 # define BOOST_INTERLOCKED_DECREMENT(dest) \
65 InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
66 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
67 InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
68 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
69 InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
70 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
71 InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
72 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
73 InterlockedCompareExchangePointer((void**)(dest), (void*)(exchange), (void*)(compare))
74 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
75 InterlockedExchangePointer((void**)(dest), (void*)(exchange))
76
77 #elif defined( BOOST_USE_INTRIN_H ) || defined( BOOST_INTERLOCKED_HAS_INTRIN_H )
78
79 #include <intrin.h>
80
81 # define BOOST_INTERLOCKED_INCREMENT(dest) \
82 _InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
83 # define BOOST_INTERLOCKED_DECREMENT(dest) \
84 _InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
85 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
86 _InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
87 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
88 _InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
89 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
90 _InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
91
92 // Note: Though MSVC-12 defines _InterlockedCompareExchangePointer and _InterlockedExchangePointer in intrin.h, the latter
93 // is actually broken as it conflicts with winnt.h from Windows SDK 8.1.
94 # if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
95 (defined(_M_IA64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_ARM64))
96
97 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
98 _InterlockedCompareExchangePointer((void**)(dest), (void*)(exchange), (void*)(compare))
99 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
100 _InterlockedExchangePointer((void**)(dest), (void*)(exchange))
101
102 # else
103
104 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
105 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare)))
106 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
107 ((void*)BOOST_INTERLOCKED_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange)))
108
109 # endif
110
111 #elif defined(_WIN32_WCE)
112
113 #if _WIN32_WCE >= 0x600
114
115 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedIncrement( BOOST_INTERLOCKED_LONG32 volatile * );
116 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedDecrement( BOOST_INTERLOCKED_LONG32 volatile * );
117 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedCompareExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32, BOOST_INTERLOCKED_LONG32 );
118 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
119 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedExchangeAdd( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
120
121 # define BOOST_INTERLOCKED_INCREMENT(dest) \
122 _InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
123 # define BOOST_INTERLOCKED_DECREMENT(dest) \
124 _InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
125 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
126 _InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
127 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
128 _InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
129 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
130 _InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
131
132 #else // _WIN32_WCE >= 0x600
133
134 // under Windows CE we still have old-style Interlocked* functions
135
136 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedIncrement( BOOST_INTERLOCKED_LONG32 * );
137 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedDecrement( BOOST_INTERLOCKED_LONG32 * );
138 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedCompareExchange( BOOST_INTERLOCKED_LONG32 *, BOOST_INTERLOCKED_LONG32, BOOST_INTERLOCKED_LONG32 );
139 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedExchange( BOOST_INTERLOCKED_LONG32 *, BOOST_INTERLOCKED_LONG32 );
140 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedExchangeAdd( BOOST_INTERLOCKED_LONG32 *, BOOST_INTERLOCKED_LONG32 );
141
142 # define BOOST_INTERLOCKED_INCREMENT(dest) \
143 InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
144 # define BOOST_INTERLOCKED_DECREMENT(dest) \
145 InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
146 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
147 InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
148 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
149 InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
150 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
151 InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
152
153 #endif // _WIN32_WCE >= 0x600
154
155 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
156 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare)))
157 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
158 ((void*)BOOST_INTERLOCKED_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange)))
159
160 #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN )
161
162 # if defined( __CLRCALL_PURE_OR_CDECL )
163 # define BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL __CLRCALL_PURE_OR_CDECL
164 # else
165 # define BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL __cdecl
166 # endif
167
168 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedIncrement( BOOST_INTERLOCKED_LONG32 volatile * );
169 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedDecrement( BOOST_INTERLOCKED_LONG32 volatile * );
170 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32, BOOST_INTERLOCKED_LONG32 );
171 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
172 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedExchangeAdd( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
173
174 # if defined( BOOST_MSVC ) && BOOST_MSVC >= 1310
175 # pragma intrinsic( _InterlockedIncrement )
176 # pragma intrinsic( _InterlockedDecrement )
177 # pragma intrinsic( _InterlockedCompareExchange )
178 # pragma intrinsic( _InterlockedExchange )
179 # pragma intrinsic( _InterlockedExchangeAdd )
180 # endif
181
182 # if defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM64)
183
184 extern "C" void* BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedCompareExchangePointer( void* volatile *, void*, void* );
185 extern "C" void* BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedExchangePointer( void* volatile *, void* );
186
187 # if defined( BOOST_MSVC ) && BOOST_MSVC >= 1310
188 # pragma intrinsic( _InterlockedCompareExchangePointer )
189 # pragma intrinsic( _InterlockedExchangePointer )
190 # endif
191
192 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
193 _InterlockedCompareExchangePointer((void**)(dest), (void*)(exchange), (void*)(compare))
194 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
195 _InterlockedExchangePointer((void**)(dest), (void*)(exchange))
196
197 # else
198
199 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
200 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare)))
201 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
202 ((void*)BOOST_INTERLOCKED_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange)))
203
204 # endif
205
206 # undef BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL
207
208 # define BOOST_INTERLOCKED_INCREMENT(dest) \
209 _InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
210 # define BOOST_INTERLOCKED_DECREMENT(dest) \
211 _InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
212 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
213 _InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
214 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
215 _InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
216 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
217 _InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
218
219 #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
220
221 #define BOOST_INTERLOCKED_IMPORT __declspec(dllimport)
222
223 namespace boost
224 {
225
226 namespace detail
227 {
228
229 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedIncrement( BOOST_INTERLOCKED_LONG32 volatile * );
230 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedDecrement( BOOST_INTERLOCKED_LONG32 volatile * );
231 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedCompareExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32, BOOST_INTERLOCKED_LONG32 );
232 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
233 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedExchangeAdd( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
234
235 # if defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM64)
236 extern "C" BOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedCompareExchangePointer( void* volatile *, void*, void* );
237 extern "C" BOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedExchangePointer( void* volatile *, void* );
238 # endif
239
240 } // namespace detail
241
242 } // namespace boost
243
244 # define BOOST_INTERLOCKED_INCREMENT(dest) \
245 ::boost::detail::InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
246 # define BOOST_INTERLOCKED_DECREMENT(dest) \
247 ::boost::detail::InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
248 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
249 ::boost::detail::InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
250 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
251 ::boost::detail::InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
252 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
253 ::boost::detail::InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
254
255 # if defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM64)
256 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
257 ::boost::detail::InterlockedCompareExchangePointer((void**)(dest), (void*)(exchange), (void*)(compare))
258 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
259 ::boost::detail::InterlockedExchangePointer((void**)(dest), (void*)(exchange))
260 # else
261 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
262 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((BOOST_INTERLOCKED_LONG32 volatile*)(dest),(BOOST_INTERLOCKED_LONG32)(exchange),(BOOST_INTERLOCKED_LONG32)(compare)))
263 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
264 ((void*)BOOST_INTERLOCKED_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest),(BOOST_INTERLOCKED_LONG32)(exchange)))
265 # endif
266
267 #else
268
269 # error "Interlocked intrinsics not available"
270
271 #endif
272
273 #endif // #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED