1 #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
\r
2 #define BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
\r
4 // MS compatible compilers support #pragma once
\r
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
\r
11 // boost/detail/interlocked.hpp
\r
13 // Copyright 2005 Peter Dimov
\r
15 // Distributed under the Boost Software License, Version 1.0. (See
\r
16 // accompanying file LICENSE_1_0.txt or copy at
\r
17 // http://www.boost.org/LICENSE_1_0.txt)
\r
20 #include <boost/config.hpp>
\r
22 #if defined( BOOST_USE_WINDOWS_H )
\r
24 # include <windows.h>
\r
26 # define BOOST_INTERLOCKED_INCREMENT InterlockedIncrement
\r
27 # define BOOST_INTERLOCKED_DECREMENT InterlockedDecrement
\r
28 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange
\r
29 # define BOOST_INTERLOCKED_EXCHANGE InterlockedExchange
\r
30 # define BOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd
\r
31 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER InterlockedCompareExchangePointer
\r
32 # define BOOST_INTERLOCKED_EXCHANGE_POINTER InterlockedExchangePointer
\r
34 #elif defined(_WIN32_WCE)
\r
36 // under Windows CE we still have old-style Interlocked* functions
\r
38 extern "C" long __cdecl InterlockedIncrement( long* );
\r
39 extern "C" long __cdecl InterlockedDecrement( long* );
\r
40 extern "C" long __cdecl InterlockedCompareExchange( long*, long, long );
\r
41 extern "C" long __cdecl InterlockedExchange( long*, long );
\r
42 extern "C" long __cdecl InterlockedExchangeAdd( long*, long );
\r
44 # define BOOST_INTERLOCKED_INCREMENT InterlockedIncrement
\r
45 # define BOOST_INTERLOCKED_DECREMENT InterlockedDecrement
\r
46 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange
\r
47 # define BOOST_INTERLOCKED_EXCHANGE InterlockedExchange
\r
48 # define BOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd
\r
50 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
\r
51 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long*)(dest),(long)(exchange),(long)(compare)))
\r
52 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
\r
53 ((void*)BOOST_INTERLOCKED_EXCHANGE((long*)(dest),(long)(exchange)))
\r
55 #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN )
\r
57 #if defined( __CLRCALL_PURE_OR_CDECL )
\r
59 extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedIncrement( long volatile * );
\r
60 extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedDecrement( long volatile * );
\r
61 extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange( long volatile *, long, long );
\r
62 extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchange( long volatile *, long );
\r
63 extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchangeAdd( long volatile *, long );
\r
67 extern "C" long __cdecl _InterlockedIncrement( long volatile * );
\r
68 extern "C" long __cdecl _InterlockedDecrement( long volatile * );
\r
69 extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long );
\r
70 extern "C" long __cdecl _InterlockedExchange( long volatile *, long );
\r
71 extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long );
\r
75 # pragma intrinsic( _InterlockedIncrement )
\r
76 # pragma intrinsic( _InterlockedDecrement )
\r
77 # pragma intrinsic( _InterlockedCompareExchange )
\r
78 # pragma intrinsic( _InterlockedExchange )
\r
79 # pragma intrinsic( _InterlockedExchangeAdd )
\r
81 # if defined(_M_IA64) || defined(_M_AMD64)
\r
83 extern "C" void* __cdecl _InterlockedCompareExchangePointer( void* volatile *, void*, void* );
\r
84 extern "C" void* __cdecl _InterlockedExchangePointer( void* volatile *, void* );
\r
86 # pragma intrinsic( _InterlockedCompareExchangePointer )
\r
87 # pragma intrinsic( _InterlockedExchangePointer )
\r
89 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER _InterlockedCompareExchangePointer
\r
90 # define BOOST_INTERLOCKED_EXCHANGE_POINTER _InterlockedExchangePointer
\r
94 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
\r
95 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
\r
96 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
\r
97 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
\r
101 # define BOOST_INTERLOCKED_INCREMENT _InterlockedIncrement
\r
102 # define BOOST_INTERLOCKED_DECREMENT _InterlockedDecrement
\r
103 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange
\r
104 # define BOOST_INTERLOCKED_EXCHANGE _InterlockedExchange
\r
105 # define BOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd
\r
107 #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
\r
115 extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement( long volatile * );
\r
116 extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement( long volatile * );
\r
117 extern "C" __declspec(dllimport) long __stdcall InterlockedCompareExchange( long volatile *, long, long );
\r
118 extern "C" __declspec(dllimport) long __stdcall InterlockedExchange( long volatile *, long );
\r
119 extern "C" __declspec(dllimport) long __stdcall InterlockedExchangeAdd( long volatile *, long );
\r
121 } // namespace detail
\r
123 } // namespace boost
\r
125 # define BOOST_INTERLOCKED_INCREMENT ::boost::detail::InterlockedIncrement
\r
126 # define BOOST_INTERLOCKED_DECREMENT ::boost::detail::InterlockedDecrement
\r
127 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE ::boost::detail::InterlockedCompareExchange
\r
128 # define BOOST_INTERLOCKED_EXCHANGE ::boost::detail::InterlockedExchange
\r
129 # define BOOST_INTERLOCKED_EXCHANGE_ADD ::boost::detail::InterlockedExchangeAdd
\r
131 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
\r
132 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
\r
133 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
\r
134 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
\r
138 # error "Interlocked intrinsics not available"
\r
142 #endif // #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
\r