Merge c:/dyninst/pc_bluegene/dyninst into dyn_pc_integration
[dyninst.git] / external / boost / detail / interlocked.hpp
1 #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED
2 #define BOOST_DETAIL_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/interlocked.hpp
12 //
13 //  Copyright 2005 Peter Dimov
14 //
15 //  Distributed under the Boost Software License, Version 1.0. (See
16 //  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 #if defined( BOOST_USE_WINDOWS_H )
23
24 # include <windows.h>
25
26 # define BOOST_INTERLOCKED_INCREMENT InterlockedIncrement
27 # define BOOST_INTERLOCKED_DECREMENT InterlockedDecrement
28 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange
29 # define BOOST_INTERLOCKED_EXCHANGE InterlockedExchange
30 # define BOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd
31 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER InterlockedCompareExchangePointer
32 # define BOOST_INTERLOCKED_EXCHANGE_POINTER InterlockedExchangePointer
33
34 #elif defined(_WIN32_WCE)
35
36 // under Windows CE we still have old-style Interlocked* functions
37
38 extern "C" long __cdecl InterlockedIncrement( long* );
39 extern "C" long __cdecl InterlockedDecrement( long* );
40 extern "C" long __cdecl InterlockedCompareExchange( long*, long, long );
41 extern "C" long __cdecl InterlockedExchange( long*, long );
42 extern "C" long __cdecl InterlockedExchangeAdd( long*, long );
43
44 # define BOOST_INTERLOCKED_INCREMENT InterlockedIncrement
45 # define BOOST_INTERLOCKED_DECREMENT InterlockedDecrement
46 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange
47 # define BOOST_INTERLOCKED_EXCHANGE InterlockedExchange
48 # define BOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd
49
50 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
51     ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long*)(dest),(long)(exchange),(long)(compare)))
52 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
53     ((void*)BOOST_INTERLOCKED_EXCHANGE((long*)(dest),(long)(exchange)))
54
55 #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN )
56
57 extern "C" long __cdecl _InterlockedIncrement( long volatile * );
58 extern "C" long __cdecl _InterlockedDecrement( long volatile * );
59 extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long );
60 extern "C" long __cdecl _InterlockedExchange( long volatile *, long);
61 extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long);
62
63 # pragma intrinsic( _InterlockedIncrement )
64 # pragma intrinsic( _InterlockedDecrement )
65 # pragma intrinsic( _InterlockedCompareExchange )
66 # pragma intrinsic( _InterlockedExchange )
67 # pragma intrinsic( _InterlockedExchangeAdd )
68
69 # if defined(_M_IA64) || defined(_M_AMD64)
70
71 extern "C" void* __cdecl _InterlockedCompareExchangePointer( void* volatile *, void*, void* );
72 extern "C" void* __cdecl _InterlockedExchangePointer( void* volatile *, void* );
73
74 #  pragma intrinsic( _InterlockedCompareExchangePointer )
75 #  pragma intrinsic( _InterlockedExchangePointer )
76
77 #  define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER _InterlockedCompareExchangePointer
78 #  define BOOST_INTERLOCKED_EXCHANGE_POINTER _InterlockedExchangePointer
79
80 # else
81
82 #  define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
83     ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
84 #  define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
85     ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
86
87 # endif
88
89 # define BOOST_INTERLOCKED_INCREMENT _InterlockedIncrement
90 # define BOOST_INTERLOCKED_DECREMENT _InterlockedDecrement
91 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange
92 # define BOOST_INTERLOCKED_EXCHANGE _InterlockedExchange
93 # define BOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd
94
95 #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
96
97 namespace boost
98 {
99
100 namespace detail
101 {
102
103 extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement( long volatile * );
104 extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement( long volatile * );
105 extern "C" __declspec(dllimport) long __stdcall InterlockedCompareExchange( long volatile *, long, long );
106 extern "C" __declspec(dllimport) long __stdcall InterlockedExchange( long volatile *, long );
107 extern "C" __declspec(dllimport) long __stdcall InterlockedExchangeAdd( long volatile *, long );
108
109 } // namespace detail
110
111 } // namespace boost
112
113 # define BOOST_INTERLOCKED_INCREMENT ::boost::detail::InterlockedIncrement
114 # define BOOST_INTERLOCKED_DECREMENT ::boost::detail::InterlockedDecrement
115 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE ::boost::detail::InterlockedCompareExchange
116 # define BOOST_INTERLOCKED_EXCHANGE ::boost::detail::InterlockedExchange
117 # define BOOST_INTERLOCKED_EXCHANGE_ADD ::boost::detail::InterlockedExchangeAdd
118
119 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
120     ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
121 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
122     ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
123
124 #else
125
126 # error "Interlocked intrinsics not available"
127
128 #endif
129
130 #endif // #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED