]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef BOOST_SMART_PTR_DETAIL_SP_INTERLOCKED_HPP_INCLUDED |
2 | #define BOOST_SMART_PTR_DETAIL_SP_INTERLOCKED_HPP_INCLUDED | |
3 | ||
4 | // MS compatible compilers support #pragma once | |
5 | ||
6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) | |
7 | # pragma once | |
8 | #endif | |
9 | ||
10 | // | |
11 | // boost/detail/sp_interlocked.hpp | |
12 | // | |
13 | // Copyright 2005, 2014 Peter Dimov | |
14 | // | |
15 | // Distributed under the Boost Software License, Version 1.0. | |
16 | // See accompanying file LICENSE_1_0.txt or copy at | |
17 | // http://www.boost.org/LICENSE_1_0.txt | |
18 | // | |
19 | ||
20 | #include <boost/config.hpp> | |
21 | ||
22 | // BOOST_SP_HAS_INTRIN_H | |
23 | ||
24 | // VC9 has intrin.h, but it collides with <utility> | |
25 | #if defined( BOOST_MSVC ) && BOOST_MSVC >= 1600 | |
26 | ||
27 | # define BOOST_SP_HAS_INTRIN_H | |
28 | ||
29 | // Unlike __MINGW64__, __MINGW64_VERSION_MAJOR is defined by MinGW-w64 for both 32 and 64-bit targets. | |
30 | #elif defined( __MINGW64_VERSION_MAJOR ) | |
31 | ||
32 | // MinGW-w64 provides intrin.h for both 32 and 64-bit targets. | |
33 | # define BOOST_SP_HAS_INTRIN_H | |
34 | ||
92f5a8d4 TL |
35 | #elif defined( __LP64__ ) |
36 | ||
37 | // We have to use intrin.h on Cygwin 64 | |
38 | # define BOOST_SP_HAS_INTRIN_H | |
39 | ||
7c673cae FG |
40 | // Intel C++ on Windows on VC10+ stdlib |
41 | #elif defined( BOOST_INTEL_WIN ) && defined( _CPPLIB_VER ) && _CPPLIB_VER >= 520 | |
42 | ||
43 | # define BOOST_SP_HAS_INTRIN_H | |
44 | ||
92f5a8d4 TL |
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_SP_HAS_INTRIN_H | |
49 | ||
7c673cae FG |
50 | #endif |
51 | ||
52 | #if defined( BOOST_USE_WINDOWS_H ) | |
53 | ||
54 | # include <windows.h> | |
55 | ||
56 | # define BOOST_SP_INTERLOCKED_INCREMENT InterlockedIncrement | |
57 | # define BOOST_SP_INTERLOCKED_DECREMENT InterlockedDecrement | |
58 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange | |
59 | # define BOOST_SP_INTERLOCKED_EXCHANGE InterlockedExchange | |
60 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd | |
61 | ||
62 | #elif defined( BOOST_USE_INTRIN_H ) || defined( BOOST_SP_HAS_INTRIN_H ) | |
63 | ||
64 | #include <intrin.h> | |
65 | ||
66 | # define BOOST_SP_INTERLOCKED_INCREMENT _InterlockedIncrement | |
67 | # define BOOST_SP_INTERLOCKED_DECREMENT _InterlockedDecrement | |
68 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange | |
69 | # define BOOST_SP_INTERLOCKED_EXCHANGE _InterlockedExchange | |
70 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd | |
71 | ||
72 | #elif defined( _WIN32_WCE ) | |
73 | ||
74 | #if _WIN32_WCE >= 0x600 | |
75 | ||
76 | extern "C" long __cdecl _InterlockedIncrement( long volatile * ); | |
77 | extern "C" long __cdecl _InterlockedDecrement( long volatile * ); | |
78 | extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long ); | |
79 | extern "C" long __cdecl _InterlockedExchange( long volatile *, long ); | |
80 | extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long ); | |
81 | ||
82 | # define BOOST_SP_INTERLOCKED_INCREMENT _InterlockedIncrement | |
83 | # define BOOST_SP_INTERLOCKED_DECREMENT _InterlockedDecrement | |
84 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange | |
85 | # define BOOST_SP_INTERLOCKED_EXCHANGE _InterlockedExchange | |
86 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd | |
87 | ||
88 | #else | |
89 | ||
90 | // under Windows CE we still have old-style Interlocked* functions | |
91 | ||
92 | extern "C" long __cdecl InterlockedIncrement( long* ); | |
93 | extern "C" long __cdecl InterlockedDecrement( long* ); | |
94 | extern "C" long __cdecl InterlockedCompareExchange( long*, long, long ); | |
95 | extern "C" long __cdecl InterlockedExchange( long*, long ); | |
96 | extern "C" long __cdecl InterlockedExchangeAdd( long*, long ); | |
97 | ||
98 | # define BOOST_SP_INTERLOCKED_INCREMENT InterlockedIncrement | |
99 | # define BOOST_SP_INTERLOCKED_DECREMENT InterlockedDecrement | |
100 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange | |
101 | # define BOOST_SP_INTERLOCKED_EXCHANGE InterlockedExchange | |
102 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd | |
103 | ||
104 | #endif | |
105 | ||
106 | #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN ) | |
107 | ||
108 | #if defined( __CLRCALL_PURE_OR_CDECL ) | |
109 | ||
110 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedIncrement( long volatile * ); | |
111 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedDecrement( long volatile * ); | |
112 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange( long volatile *, long, long ); | |
113 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchange( long volatile *, long ); | |
114 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchangeAdd( long volatile *, long ); | |
115 | ||
116 | #else | |
117 | ||
118 | extern "C" long __cdecl _InterlockedIncrement( long volatile * ); | |
119 | extern "C" long __cdecl _InterlockedDecrement( long volatile * ); | |
120 | extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long ); | |
121 | extern "C" long __cdecl _InterlockedExchange( long volatile *, long ); | |
122 | extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long ); | |
123 | ||
124 | # if defined( BOOST_MSVC ) && BOOST_MSVC == 1310 | |
125 | //From MSDN, Visual Studio .NET 2003 spedific: To declare one of the interlocked functions | |
126 | //for use as an intrinsic, the function must be declared with the leading underscore and | |
127 | //the new function must appear in a #pragma intrinsic statement. | |
128 | # pragma intrinsic( _InterlockedIncrement ) | |
129 | # pragma intrinsic( _InterlockedDecrement ) | |
130 | # pragma intrinsic( _InterlockedCompareExchange ) | |
131 | # pragma intrinsic( _InterlockedExchange ) | |
132 | # pragma intrinsic( _InterlockedExchangeAdd ) | |
133 | # endif | |
134 | ||
135 | #endif | |
136 | ||
137 | # define BOOST_SP_INTERLOCKED_INCREMENT _InterlockedIncrement | |
138 | # define BOOST_SP_INTERLOCKED_DECREMENT _InterlockedDecrement | |
139 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange | |
140 | # define BOOST_SP_INTERLOCKED_EXCHANGE _InterlockedExchange | |
141 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd | |
142 | ||
143 | #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) | |
144 | ||
145 | namespace boost | |
146 | { | |
147 | ||
148 | namespace detail | |
149 | { | |
150 | ||
151 | extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement( long volatile * ); | |
152 | extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement( long volatile * ); | |
153 | extern "C" __declspec(dllimport) long __stdcall InterlockedCompareExchange( long volatile *, long, long ); | |
154 | extern "C" __declspec(dllimport) long __stdcall InterlockedExchange( long volatile *, long ); | |
155 | extern "C" __declspec(dllimport) long __stdcall InterlockedExchangeAdd( long volatile *, long ); | |
156 | ||
157 | } // namespace detail | |
158 | ||
159 | } // namespace boost | |
160 | ||
161 | # define BOOST_SP_INTERLOCKED_INCREMENT ::boost::detail::InterlockedIncrement | |
162 | # define BOOST_SP_INTERLOCKED_DECREMENT ::boost::detail::InterlockedDecrement | |
163 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE ::boost::detail::InterlockedCompareExchange | |
164 | # define BOOST_SP_INTERLOCKED_EXCHANGE ::boost::detail::InterlockedExchange | |
165 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD ::boost::detail::InterlockedExchangeAdd | |
166 | ||
167 | #else | |
168 | ||
169 | # error "Interlocked intrinsics not available" | |
170 | ||
171 | #endif | |
172 | ||
173 | #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_INTERLOCKED_HPP_INCLUDED |