Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:45:53

0001 #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
0002 #define BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
0003 
0004 //
0005 //  boost/detail/interlocked.hpp
0006 //
0007 //  Copyright 2005 Peter Dimov
0008 //  Copyright 2018, 2019 Andrey Semashev
0009 //
0010 //  Distributed under the Boost Software License, Version 1.0. (See
0011 //  accompanying file LICENSE_1_0.txt or copy at
0012 //  http://www.boost.org/LICENSE_1_0.txt)
0013 //
0014 
0015 #include <boost/config.hpp>
0016 
0017 #ifdef BOOST_HAS_PRAGMA_ONCE
0018 #pragma once
0019 #endif
0020 
0021 // BOOST_INTERLOCKED_HAS_INTRIN_H
0022 
0023 // VC9 has intrin.h, but it collides with <utility>
0024 #if defined( BOOST_MSVC ) && BOOST_MSVC >= 1600
0025 
0026 # define BOOST_INTERLOCKED_HAS_INTRIN_H
0027 
0028 // Unlike __MINGW64__, __MINGW64_VERSION_MAJOR is defined by MinGW-w64 for both 32 and 64-bit targets.
0029 #elif defined( __MINGW64_VERSION_MAJOR )
0030 
0031 // MinGW-w64 provides intrin.h for both 32 and 64-bit targets.
0032 # define BOOST_INTERLOCKED_HAS_INTRIN_H
0033 
0034 #elif defined( __CYGWIN__ )
0035 
0036 // Cygwin and Cygwin64 provide intrin.h. On Cygwin64 we have to use intrin.h because it's an LP64 target,
0037 // where long is 64-bit and therefore _Interlocked* functions have different signatures.
0038 # define BOOST_INTERLOCKED_HAS_INTRIN_H
0039 
0040 // Intel C++ on Windows on VC10+ stdlib
0041 #elif defined( BOOST_INTEL_WIN ) && defined( _CPPLIB_VER ) && _CPPLIB_VER >= 520
0042 
0043 # define BOOST_INTERLOCKED_HAS_INTRIN_H
0044 
0045 // clang-cl on Windows on VC10+ stdlib
0046 #elif defined( __clang__ ) && defined( _MSC_VER ) && defined( _CPPLIB_VER ) && _CPPLIB_VER >= 520
0047 
0048 # define BOOST_INTERLOCKED_HAS_INTRIN_H
0049 
0050 #endif
0051 
0052 #if !defined(__LP64__)
0053 #define BOOST_INTERLOCKED_LONG32 long
0054 #else
0055 #define BOOST_INTERLOCKED_LONG32 int
0056 #endif
0057 
0058 #if defined( BOOST_USE_WINDOWS_H )
0059 
0060 # include <windows.h>
0061 
0062 # define BOOST_INTERLOCKED_INCREMENT(dest) \
0063     InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
0064 # define BOOST_INTERLOCKED_DECREMENT(dest) \
0065     InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
0066 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
0067     InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
0068 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
0069     InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
0070 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
0071     InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
0072 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
0073     InterlockedCompareExchangePointer((void**)(dest), (void*)(exchange), (void*)(compare))
0074 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
0075     InterlockedExchangePointer((void**)(dest), (void*)(exchange))
0076 
0077 #elif defined( BOOST_USE_INTRIN_H ) || defined( BOOST_INTERLOCKED_HAS_INTRIN_H )
0078 
0079 #include <intrin.h>
0080 
0081 # define BOOST_INTERLOCKED_INCREMENT(dest) \
0082     _InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
0083 # define BOOST_INTERLOCKED_DECREMENT(dest) \
0084     _InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
0085 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
0086     _InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
0087 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
0088     _InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
0089 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
0090     _InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
0091 
0092 // Note: Though MSVC-12 defines _InterlockedCompareExchangePointer and _InterlockedExchangePointer in intrin.h, the latter
0093 //       is actually broken as it conflicts with winnt.h from Windows SDK 8.1.
0094 # if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
0095   (defined(_M_IA64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_ARM64))
0096 
0097 #  define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
0098      _InterlockedCompareExchangePointer((void**)(dest), (void*)(exchange), (void*)(compare))
0099 #  define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
0100      _InterlockedExchangePointer((void**)(dest), (void*)(exchange))
0101 
0102 # else
0103 
0104 #  define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
0105     ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare)))
0106 #  define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
0107     ((void*)BOOST_INTERLOCKED_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange)))
0108 
0109 # endif
0110 
0111 #elif defined(_WIN32_WCE)
0112 
0113 #if _WIN32_WCE >= 0x600
0114 
0115 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedIncrement( BOOST_INTERLOCKED_LONG32 volatile * );
0116 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedDecrement( BOOST_INTERLOCKED_LONG32 volatile * );
0117 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedCompareExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32, BOOST_INTERLOCKED_LONG32 );
0118 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
0119 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl _InterlockedExchangeAdd( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
0120 
0121 # define BOOST_INTERLOCKED_INCREMENT(dest) \
0122     _InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
0123 # define BOOST_INTERLOCKED_DECREMENT(dest) \
0124     _InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
0125 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
0126     _InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
0127 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
0128     _InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
0129 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
0130     _InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
0131 
0132 #else // _WIN32_WCE >= 0x600
0133 
0134 // under Windows CE we still have old-style Interlocked* functions
0135 
0136 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedIncrement( BOOST_INTERLOCKED_LONG32 * );
0137 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedDecrement( BOOST_INTERLOCKED_LONG32 * );
0138 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedCompareExchange( BOOST_INTERLOCKED_LONG32 *, BOOST_INTERLOCKED_LONG32, BOOST_INTERLOCKED_LONG32 );
0139 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedExchange( BOOST_INTERLOCKED_LONG32 *, BOOST_INTERLOCKED_LONG32 );
0140 extern "C" BOOST_INTERLOCKED_LONG32 __cdecl InterlockedExchangeAdd( BOOST_INTERLOCKED_LONG32 *, BOOST_INTERLOCKED_LONG32 );
0141 
0142 # define BOOST_INTERLOCKED_INCREMENT(dest) \
0143     InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
0144 # define BOOST_INTERLOCKED_DECREMENT(dest) \
0145     InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
0146 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
0147     InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
0148 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
0149     InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
0150 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
0151     InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
0152 
0153 #endif // _WIN32_WCE >= 0x600
0154 
0155 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
0156     ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare)))
0157 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
0158     ((void*)BOOST_INTERLOCKED_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange)))
0159 
0160 #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN )
0161 
0162 # if defined( __CLRCALL_PURE_OR_CDECL )
0163 #  define BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL __CLRCALL_PURE_OR_CDECL
0164 # else
0165 #  define BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL __cdecl
0166 # endif
0167 
0168 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedIncrement( BOOST_INTERLOCKED_LONG32 volatile * );
0169 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedDecrement( BOOST_INTERLOCKED_LONG32 volatile * );
0170 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32, BOOST_INTERLOCKED_LONG32 );
0171 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
0172 extern "C" BOOST_INTERLOCKED_LONG32 BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedExchangeAdd( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
0173 
0174 # if defined( BOOST_MSVC ) && BOOST_MSVC >= 1310
0175 #  pragma intrinsic( _InterlockedIncrement )
0176 #  pragma intrinsic( _InterlockedDecrement )
0177 #  pragma intrinsic( _InterlockedCompareExchange )
0178 #  pragma intrinsic( _InterlockedExchange )
0179 #  pragma intrinsic( _InterlockedExchangeAdd )
0180 # endif
0181 
0182 # if defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM64)
0183 
0184 extern "C" void* BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedCompareExchangePointer( void* volatile *, void*, void* );
0185 extern "C" void* BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL _InterlockedExchangePointer( void* volatile *, void* );
0186 
0187 #  if defined( BOOST_MSVC ) && BOOST_MSVC >= 1310
0188 #   pragma intrinsic( _InterlockedCompareExchangePointer )
0189 #   pragma intrinsic( _InterlockedExchangePointer )
0190 #  endif
0191 
0192 #  define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
0193      _InterlockedCompareExchangePointer((void**)(dest), (void*)(exchange), (void*)(compare))
0194 #  define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
0195      _InterlockedExchangePointer((void**)(dest), (void*)(exchange))
0196 
0197 # else
0198 
0199 #  define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
0200     ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare)))
0201 #  define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
0202     ((void*)BOOST_INTERLOCKED_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange)))
0203 
0204 # endif
0205 
0206 # undef BOOST_INTERLOCKED_CLRCALL_PURE_OR_CDECL
0207 
0208 # define BOOST_INTERLOCKED_INCREMENT(dest) \
0209     _InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
0210 # define BOOST_INTERLOCKED_DECREMENT(dest) \
0211     _InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
0212 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
0213     _InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
0214 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
0215     _InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
0216 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
0217     _InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
0218 
0219 #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
0220 
0221 #define BOOST_INTERLOCKED_IMPORT __declspec(dllimport)
0222 
0223 namespace boost
0224 {
0225 
0226 namespace detail
0227 {
0228 
0229 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedIncrement( BOOST_INTERLOCKED_LONG32 volatile * );
0230 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedDecrement( BOOST_INTERLOCKED_LONG32 volatile * );
0231 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedCompareExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32, BOOST_INTERLOCKED_LONG32 );
0232 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedExchange( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
0233 extern "C" BOOST_INTERLOCKED_IMPORT BOOST_INTERLOCKED_LONG32 __stdcall InterlockedExchangeAdd( BOOST_INTERLOCKED_LONG32 volatile *, BOOST_INTERLOCKED_LONG32 );
0234 
0235 # if defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM64)
0236 extern "C" BOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedCompareExchangePointer( void* volatile *, void*, void* );
0237 extern "C" BOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedExchangePointer( void* volatile *, void* );
0238 # endif
0239 
0240 } // namespace detail
0241 
0242 } // namespace boost
0243 
0244 # define BOOST_INTERLOCKED_INCREMENT(dest) \
0245     ::boost::detail::InterlockedIncrement((BOOST_INTERLOCKED_LONG32*)(dest))
0246 # define BOOST_INTERLOCKED_DECREMENT(dest) \
0247     ::boost::detail::InterlockedDecrement((BOOST_INTERLOCKED_LONG32*)(dest))
0248 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE(dest, exchange, compare) \
0249     ::boost::detail::InterlockedCompareExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange), (BOOST_INTERLOCKED_LONG32)(compare))
0250 # define BOOST_INTERLOCKED_EXCHANGE(dest, exchange) \
0251     ::boost::detail::InterlockedExchange((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(exchange))
0252 # define BOOST_INTERLOCKED_EXCHANGE_ADD(dest, add) \
0253     ::boost::detail::InterlockedExchangeAdd((BOOST_INTERLOCKED_LONG32*)(dest), (BOOST_INTERLOCKED_LONG32)(add))
0254 
0255 # if defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM64)
0256 #  define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
0257      ::boost::detail::InterlockedCompareExchangePointer((void**)(dest), (void*)(exchange), (void*)(compare))
0258 #  define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
0259      ::boost::detail::InterlockedExchangePointer((void**)(dest), (void*)(exchange))
0260 # else
0261 #  define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest, exchange, compare) \
0262     ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((BOOST_INTERLOCKED_LONG32 volatile*)(dest),(BOOST_INTERLOCKED_LONG32)(exchange),(BOOST_INTERLOCKED_LONG32)(compare)))
0263 #  define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest, exchange) \
0264     ((void*)BOOST_INTERLOCKED_EXCHANGE((BOOST_INTERLOCKED_LONG32*)(dest),(BOOST_INTERLOCKED_LONG32)(exchange)))
0265 # endif
0266 
0267 #else
0268 
0269 # error "Interlocked intrinsics not available"
0270 
0271 #endif
0272 
0273 #endif // #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED