1 #ifndef BOOST_SMART_PTR_DETAIL_SP_INTERLOCKED_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_INTERLOCKED_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // boost/detail/sp_interlocked.hpp
13 // Copyright 2005, 2014 Peter Dimov
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
20 #include <boost/config.hpp>
22 // BOOST_SP_HAS_INTRIN_H
24 // VC9 has intrin.h, but it collides with <utility>
25 #if defined( BOOST_MSVC ) && BOOST_MSVC >= 1600
27 # define BOOST_SP_HAS_INTRIN_H
29 // Unlike __MINGW64__, __MINGW64_VERSION_MAJOR is defined by MinGW-w64 for both 32 and 64-bit targets.
30 #elif defined( __MINGW64_VERSION_MAJOR )
32 // MinGW-w64 provides intrin.h for both 32 and 64-bit targets.
33 # define BOOST_SP_HAS_INTRIN_H
35 #elif defined( __LP64__ )
37 // We have to use intrin.h on Cygwin 64
38 # define BOOST_SP_HAS_INTRIN_H
40 // Intel C++ on Windows on VC10+ stdlib
41 #elif defined( BOOST_INTEL_WIN ) && defined( _CPPLIB_VER ) && _CPPLIB_VER >= 520
43 # define BOOST_SP_HAS_INTRIN_H
45 // clang-cl on Windows on VC10+ stdlib
46 #elif defined( __clang__ ) && defined( _MSC_VER ) && defined( _CPPLIB_VER ) && _CPPLIB_VER >= 520
48 # define BOOST_SP_HAS_INTRIN_H
52 #if defined( BOOST_USE_WINDOWS_H )
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
62 #elif defined( BOOST_USE_INTRIN_H ) || defined( BOOST_SP_HAS_INTRIN_H )
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
72 #elif defined( _WIN32_WCE )
74 #if _WIN32_WCE >= 0x600
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 );
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
90 // under Windows CE we still have old-style Interlocked* functions
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 );
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
106 #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN )
108 #if defined( __CLRCALL_PURE_OR_CDECL )
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 );
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 );
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 )
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
143 #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
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 );
157 } // namespace detail
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
169 # error "Interlocked intrinsics not available"
173 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_INTERLOCKED_HPP_INCLUDED