]>
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 | ||
35 | // Intel C++ on Windows on VC10+ stdlib | |
36 | #elif defined( BOOST_INTEL_WIN ) && defined( _CPPLIB_VER ) && _CPPLIB_VER >= 520 | |
37 | ||
38 | # define BOOST_SP_HAS_INTRIN_H | |
39 | ||
40 | #endif | |
41 | ||
42 | #if defined( BOOST_USE_WINDOWS_H ) | |
43 | ||
44 | # include <windows.h> | |
45 | ||
46 | # define BOOST_SP_INTERLOCKED_INCREMENT InterlockedIncrement | |
47 | # define BOOST_SP_INTERLOCKED_DECREMENT InterlockedDecrement | |
48 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange | |
49 | # define BOOST_SP_INTERLOCKED_EXCHANGE InterlockedExchange | |
50 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd | |
51 | ||
52 | #elif defined( BOOST_USE_INTRIN_H ) || defined( BOOST_SP_HAS_INTRIN_H ) | |
53 | ||
54 | #include <intrin.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( _WIN32_WCE ) | |
63 | ||
64 | #if _WIN32_WCE >= 0x600 | |
65 | ||
66 | extern "C" long __cdecl _InterlockedIncrement( long volatile * ); | |
67 | extern "C" long __cdecl _InterlockedDecrement( long volatile * ); | |
68 | extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long ); | |
69 | extern "C" long __cdecl _InterlockedExchange( long volatile *, long ); | |
70 | extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long ); | |
71 | ||
72 | # define BOOST_SP_INTERLOCKED_INCREMENT _InterlockedIncrement | |
73 | # define BOOST_SP_INTERLOCKED_DECREMENT _InterlockedDecrement | |
74 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange | |
75 | # define BOOST_SP_INTERLOCKED_EXCHANGE _InterlockedExchange | |
76 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd | |
77 | ||
78 | #else | |
79 | ||
80 | // under Windows CE we still have old-style Interlocked* functions | |
81 | ||
82 | extern "C" long __cdecl InterlockedIncrement( long* ); | |
83 | extern "C" long __cdecl InterlockedDecrement( long* ); | |
84 | extern "C" long __cdecl InterlockedCompareExchange( long*, long, long ); | |
85 | extern "C" long __cdecl InterlockedExchange( long*, long ); | |
86 | extern "C" long __cdecl InterlockedExchangeAdd( long*, long ); | |
87 | ||
88 | # define BOOST_SP_INTERLOCKED_INCREMENT InterlockedIncrement | |
89 | # define BOOST_SP_INTERLOCKED_DECREMENT InterlockedDecrement | |
90 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange | |
91 | # define BOOST_SP_INTERLOCKED_EXCHANGE InterlockedExchange | |
92 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd | |
93 | ||
94 | #endif | |
95 | ||
96 | #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN ) | |
97 | ||
98 | #if defined( __CLRCALL_PURE_OR_CDECL ) | |
99 | ||
100 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedIncrement( long volatile * ); | |
101 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedDecrement( long volatile * ); | |
102 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange( long volatile *, long, long ); | |
103 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchange( long volatile *, long ); | |
104 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchangeAdd( long volatile *, long ); | |
105 | ||
106 | #else | |
107 | ||
108 | extern "C" long __cdecl _InterlockedIncrement( long volatile * ); | |
109 | extern "C" long __cdecl _InterlockedDecrement( long volatile * ); | |
110 | extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long ); | |
111 | extern "C" long __cdecl _InterlockedExchange( long volatile *, long ); | |
112 | extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long ); | |
113 | ||
114 | # if defined( BOOST_MSVC ) && BOOST_MSVC == 1310 | |
115 | //From MSDN, Visual Studio .NET 2003 spedific: To declare one of the interlocked functions | |
116 | //for use as an intrinsic, the function must be declared with the leading underscore and | |
117 | //the new function must appear in a #pragma intrinsic statement. | |
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 | # define BOOST_SP_INTERLOCKED_INCREMENT _InterlockedIncrement | |
128 | # define BOOST_SP_INTERLOCKED_DECREMENT _InterlockedDecrement | |
129 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange | |
130 | # define BOOST_SP_INTERLOCKED_EXCHANGE _InterlockedExchange | |
131 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd | |
132 | ||
133 | #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) | |
134 | ||
135 | namespace boost | |
136 | { | |
137 | ||
138 | namespace detail | |
139 | { | |
140 | ||
141 | extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement( long volatile * ); | |
142 | extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement( long volatile * ); | |
143 | extern "C" __declspec(dllimport) long __stdcall InterlockedCompareExchange( long volatile *, long, long ); | |
144 | extern "C" __declspec(dllimport) long __stdcall InterlockedExchange( long volatile *, long ); | |
145 | extern "C" __declspec(dllimport) long __stdcall InterlockedExchangeAdd( long volatile *, long ); | |
146 | ||
147 | } // namespace detail | |
148 | ||
149 | } // namespace boost | |
150 | ||
151 | # define BOOST_SP_INTERLOCKED_INCREMENT ::boost::detail::InterlockedIncrement | |
152 | # define BOOST_SP_INTERLOCKED_DECREMENT ::boost::detail::InterlockedDecrement | |
153 | # define BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE ::boost::detail::InterlockedCompareExchange | |
154 | # define BOOST_SP_INTERLOCKED_EXCHANGE ::boost::detail::InterlockedExchange | |
155 | # define BOOST_SP_INTERLOCKED_EXCHANGE_ADD ::boost::detail::InterlockedExchangeAdd | |
156 | ||
157 | #else | |
158 | ||
159 | # error "Interlocked intrinsics not available" | |
160 | ||
161 | #endif | |
162 | ||
163 | #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_INTERLOCKED_HPP_INCLUDED |