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