Chris@16
|
1 #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
|
Chris@16
|
2 #define BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
|
Chris@16
|
3
|
Chris@16
|
4 //
|
Chris@16
|
5 // boost/detail/interlocked.hpp
|
Chris@16
|
6 //
|
Chris@16
|
7 // Copyright 2005 Peter Dimov
|
Chris@16
|
8 //
|
Chris@16
|
9 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
10 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
11 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
12 //
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/config.hpp>
|
Chris@16
|
15
|
Chris@16
|
16 // MS compatible compilers support #pragma once
|
Chris@16
|
17 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
18 #pragma once
|
Chris@16
|
19 #endif
|
Chris@16
|
20
|
Chris@16
|
21 #if defined( BOOST_USE_WINDOWS_H )
|
Chris@16
|
22
|
Chris@16
|
23 # include <windows.h>
|
Chris@16
|
24
|
Chris@16
|
25 # define BOOST_INTERLOCKED_INCREMENT InterlockedIncrement
|
Chris@16
|
26 # define BOOST_INTERLOCKED_DECREMENT InterlockedDecrement
|
Chris@16
|
27 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange
|
Chris@16
|
28 # define BOOST_INTERLOCKED_EXCHANGE InterlockedExchange
|
Chris@16
|
29 # define BOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd
|
Chris@16
|
30 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER InterlockedCompareExchangePointer
|
Chris@16
|
31 # define BOOST_INTERLOCKED_EXCHANGE_POINTER InterlockedExchangePointer
|
Chris@16
|
32
|
Chris@16
|
33 #elif defined( BOOST_USE_INTRIN_H )
|
Chris@16
|
34
|
Chris@16
|
35 #include <intrin.h>
|
Chris@16
|
36
|
Chris@16
|
37 # define BOOST_INTERLOCKED_INCREMENT _InterlockedIncrement
|
Chris@16
|
38 # define BOOST_INTERLOCKED_DECREMENT _InterlockedDecrement
|
Chris@16
|
39 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange
|
Chris@16
|
40 # define BOOST_INTERLOCKED_EXCHANGE _InterlockedExchange
|
Chris@16
|
41 # define BOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd
|
Chris@16
|
42
|
Chris@16
|
43 # if defined(_M_IA64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__x86_64)
|
Chris@16
|
44
|
Chris@16
|
45 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER _InterlockedCompareExchangePointer
|
Chris@16
|
46 # define BOOST_INTERLOCKED_EXCHANGE_POINTER _InterlockedExchangePointer
|
Chris@16
|
47
|
Chris@16
|
48 # else
|
Chris@16
|
49
|
Chris@16
|
50 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
|
Chris@16
|
51 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
|
Chris@16
|
52 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
|
Chris@16
|
53 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
|
Chris@16
|
54
|
Chris@16
|
55 # endif
|
Chris@16
|
56
|
Chris@16
|
57 #elif defined(_WIN32_WCE)
|
Chris@16
|
58
|
Chris@16
|
59 #if _WIN32_WCE >= 0x600
|
Chris@16
|
60
|
Chris@16
|
61 extern "C" long __cdecl _InterlockedIncrement( long volatile * );
|
Chris@16
|
62 extern "C" long __cdecl _InterlockedDecrement( long volatile * );
|
Chris@16
|
63 extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long );
|
Chris@16
|
64 extern "C" long __cdecl _InterlockedExchange( long volatile *, long );
|
Chris@16
|
65 extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long );
|
Chris@16
|
66
|
Chris@16
|
67 # define BOOST_INTERLOCKED_INCREMENT _InterlockedIncrement
|
Chris@16
|
68 # define BOOST_INTERLOCKED_DECREMENT _InterlockedDecrement
|
Chris@16
|
69 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange
|
Chris@16
|
70 # define BOOST_INTERLOCKED_EXCHANGE _InterlockedExchange
|
Chris@16
|
71 # define BOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd
|
Chris@16
|
72
|
Chris@16
|
73 #else
|
Chris@16
|
74 // under Windows CE we still have old-style Interlocked* functions
|
Chris@16
|
75
|
Chris@16
|
76 extern "C" long __cdecl InterlockedIncrement( long* );
|
Chris@16
|
77 extern "C" long __cdecl InterlockedDecrement( long* );
|
Chris@16
|
78 extern "C" long __cdecl InterlockedCompareExchange( long*, long, long );
|
Chris@16
|
79 extern "C" long __cdecl InterlockedExchange( long*, long );
|
Chris@16
|
80 extern "C" long __cdecl InterlockedExchangeAdd( long*, long );
|
Chris@16
|
81
|
Chris@16
|
82 # define BOOST_INTERLOCKED_INCREMENT InterlockedIncrement
|
Chris@16
|
83 # define BOOST_INTERLOCKED_DECREMENT InterlockedDecrement
|
Chris@16
|
84 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange
|
Chris@16
|
85 # define BOOST_INTERLOCKED_EXCHANGE InterlockedExchange
|
Chris@16
|
86 # define BOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd
|
Chris@16
|
87
|
Chris@16
|
88 #endif
|
Chris@16
|
89
|
Chris@16
|
90 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
|
Chris@16
|
91 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long*)(dest),(long)(exchange),(long)(compare)))
|
Chris@16
|
92 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
|
Chris@16
|
93 ((void*)BOOST_INTERLOCKED_EXCHANGE((long*)(dest),(long)(exchange)))
|
Chris@16
|
94
|
Chris@16
|
95 #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN )
|
Chris@16
|
96
|
Chris@101
|
97 #if defined( BOOST_MSVC ) && BOOST_MSVC >= 1400
|
Chris@16
|
98
|
Chris@16
|
99 #include <intrin.h>
|
Chris@16
|
100
|
Chris@16
|
101 #else
|
Chris@16
|
102
|
Chris@101
|
103 # if defined( __CLRCALL_PURE_OR_CDECL )
|
Chris@101
|
104 # define BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL __CLRCALL_PURE_OR_CDECL
|
Chris@101
|
105 # else
|
Chris@101
|
106 # define BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL __cdecl
|
Chris@101
|
107 # endif
|
Chris@101
|
108
|
Chris@101
|
109 extern "C" long BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedIncrement( long volatile * );
|
Chris@101
|
110 extern "C" long BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedDecrement( long volatile * );
|
Chris@101
|
111 extern "C" long BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange( long volatile *, long, long );
|
Chris@101
|
112 extern "C" long BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedExchange( long volatile *, long );
|
Chris@101
|
113 extern "C" long BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedExchangeAdd( long volatile *, long );
|
Chris@101
|
114
|
Chris@101
|
115 # undef BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL
|
Chris@101
|
116
|
Chris@101
|
117 # if defined( BOOST_MSVC ) && BOOST_MSVC >= 1310
|
Chris@101
|
118 # pragma intrinsic( _InterlockedIncrement )
|
Chris@101
|
119 # pragma intrinsic( _InterlockedDecrement )
|
Chris@101
|
120 # pragma intrinsic( _InterlockedCompareExchange )
|
Chris@101
|
121 # pragma intrinsic( _InterlockedExchange )
|
Chris@101
|
122 # pragma intrinsic( _InterlockedExchangeAdd )
|
Chris@101
|
123 # endif
|
Chris@16
|
124
|
Chris@16
|
125 #endif
|
Chris@16
|
126
|
Chris@16
|
127 # if defined(_M_IA64) || defined(_M_AMD64)
|
Chris@16
|
128
|
Chris@16
|
129 extern "C" void* __cdecl _InterlockedCompareExchangePointer( void* volatile *, void*, void* );
|
Chris@16
|
130 extern "C" void* __cdecl _InterlockedExchangePointer( void* volatile *, void* );
|
Chris@16
|
131
|
Chris@16
|
132 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER _InterlockedCompareExchangePointer
|
Chris@16
|
133 # define BOOST_INTERLOCKED_EXCHANGE_POINTER _InterlockedExchangePointer
|
Chris@16
|
134
|
Chris@16
|
135 # else
|
Chris@16
|
136
|
Chris@16
|
137 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
|
Chris@16
|
138 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
|
Chris@16
|
139 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
|
Chris@16
|
140 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
|
Chris@16
|
141
|
Chris@16
|
142 # endif
|
Chris@16
|
143
|
Chris@16
|
144 # define BOOST_INTERLOCKED_INCREMENT _InterlockedIncrement
|
Chris@16
|
145 # define BOOST_INTERLOCKED_DECREMENT _InterlockedDecrement
|
Chris@16
|
146 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange
|
Chris@16
|
147 # define BOOST_INTERLOCKED_EXCHANGE _InterlockedExchange
|
Chris@16
|
148 # define BOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd
|
Chris@16
|
149
|
Chris@16
|
150 // Unlike __MINGW64__, __MINGW64_VERSION_MAJOR is defined by MinGW-w64 for both 32 and 64-bit targets.
|
Chris@16
|
151 #elif defined(__MINGW64_VERSION_MAJOR)
|
Chris@16
|
152
|
Chris@16
|
153 // MinGW-w64 provides intrin.h for both 32 and 64-bit targets.
|
Chris@16
|
154 #include <intrin.h>
|
Chris@16
|
155
|
Chris@16
|
156 # define BOOST_INTERLOCKED_INCREMENT _InterlockedIncrement
|
Chris@16
|
157 # define BOOST_INTERLOCKED_DECREMENT _InterlockedDecrement
|
Chris@16
|
158 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange
|
Chris@16
|
159 # define BOOST_INTERLOCKED_EXCHANGE _InterlockedExchange
|
Chris@16
|
160 # define BOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd
|
Chris@16
|
161 # if defined(__x86_64__) || defined(__x86_64)
|
Chris@16
|
162 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER _InterlockedCompareExchangePointer
|
Chris@16
|
163 # define BOOST_INTERLOCKED_EXCHANGE_POINTER _InterlockedExchangePointer
|
Chris@16
|
164 # else
|
Chris@16
|
165 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
|
Chris@16
|
166 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
|
Chris@16
|
167 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
|
Chris@16
|
168 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
|
Chris@16
|
169 # endif
|
Chris@16
|
170
|
Chris@16
|
171 #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
|
Chris@16
|
172
|
Chris@16
|
173 #define BOOST_INTERLOCKED_IMPORT __declspec(dllimport)
|
Chris@16
|
174
|
Chris@16
|
175 namespace boost
|
Chris@16
|
176 {
|
Chris@16
|
177
|
Chris@16
|
178 namespace detail
|
Chris@16
|
179 {
|
Chris@16
|
180
|
Chris@16
|
181 extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedIncrement( long volatile * );
|
Chris@16
|
182 extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedDecrement( long volatile * );
|
Chris@16
|
183 extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedCompareExchange( long volatile *, long, long );
|
Chris@16
|
184 extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedExchange( long volatile *, long );
|
Chris@16
|
185 extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedExchangeAdd( long volatile *, long );
|
Chris@16
|
186
|
Chris@16
|
187 # if defined(_M_IA64) || defined(_M_AMD64)
|
Chris@16
|
188 extern "C" BOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedCompareExchangePointer( void* volatile *, void*, void* );
|
Chris@16
|
189 extern "C" BOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedExchangePointer( void* volatile *, void* );
|
Chris@16
|
190 # endif
|
Chris@16
|
191
|
Chris@16
|
192 } // namespace detail
|
Chris@16
|
193
|
Chris@16
|
194 } // namespace boost
|
Chris@16
|
195
|
Chris@16
|
196 # define BOOST_INTERLOCKED_INCREMENT ::boost::detail::InterlockedIncrement
|
Chris@16
|
197 # define BOOST_INTERLOCKED_DECREMENT ::boost::detail::InterlockedDecrement
|
Chris@16
|
198 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE ::boost::detail::InterlockedCompareExchange
|
Chris@16
|
199 # define BOOST_INTERLOCKED_EXCHANGE ::boost::detail::InterlockedExchange
|
Chris@16
|
200 # define BOOST_INTERLOCKED_EXCHANGE_ADD ::boost::detail::InterlockedExchangeAdd
|
Chris@16
|
201
|
Chris@16
|
202 # if defined(_M_IA64) || defined(_M_AMD64)
|
Chris@16
|
203 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER ::boost::detail::InterlockedCompareExchangePointer
|
Chris@16
|
204 # define BOOST_INTERLOCKED_EXCHANGE_POINTER ::boost::detail::InterlockedExchangePointer
|
Chris@16
|
205 # else
|
Chris@16
|
206 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
|
Chris@16
|
207 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
|
Chris@16
|
208 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
|
Chris@16
|
209 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
|
Chris@16
|
210 # endif
|
Chris@16
|
211
|
Chris@16
|
212 #else
|
Chris@16
|
213
|
Chris@16
|
214 # error "Interlocked intrinsics not available"
|
Chris@16
|
215
|
Chris@16
|
216 #endif
|
Chris@16
|
217
|
Chris@16
|
218 #endif // #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
|