|
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 #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN ) |
|
51 |
|
52 extern "C" long __cdecl _InterlockedIncrement( long volatile * ); |
|
53 extern "C" long __cdecl _InterlockedDecrement( long volatile * ); |
|
54 extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long ); |
|
55 extern "C" long __cdecl _InterlockedExchange( long volatile *, long); |
|
56 extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long); |
|
57 |
|
58 # pragma intrinsic( _InterlockedIncrement ) |
|
59 # pragma intrinsic( _InterlockedDecrement ) |
|
60 # pragma intrinsic( _InterlockedCompareExchange ) |
|
61 # pragma intrinsic( _InterlockedExchange ) |
|
62 # pragma intrinsic( _InterlockedExchangeAdd ) |
|
63 |
|
64 # if defined(_M_IA64) || defined(_M_AMD64) |
|
65 |
|
66 extern "C" void* __cdecl _InterlockedCompareExchangePointer( void* volatile *, void*, void* ); |
|
67 extern "C" void* __cdecl _InterlockedExchangePointer( void* volatile *, void* ); |
|
68 |
|
69 # pragma intrinsic( _InterlockedCompareExchangePointer ) |
|
70 # pragma intrinsic( _InterlockedExchangePointer ) |
|
71 |
|
72 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER _InterlockedCompareExchangePointer |
|
73 # define BOOST_INTERLOCKED_EXCHANGE_POINTER _InterlockedExchangePointer |
|
74 |
|
75 # else |
|
76 |
|
77 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \ |
|
78 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare))) |
|
79 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \ |
|
80 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange))) |
|
81 |
|
82 # endif |
|
83 |
|
84 # define BOOST_INTERLOCKED_INCREMENT _InterlockedIncrement |
|
85 # define BOOST_INTERLOCKED_DECREMENT _InterlockedDecrement |
|
86 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange |
|
87 # define BOOST_INTERLOCKED_EXCHANGE _InterlockedExchange |
|
88 # define BOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd |
|
89 |
|
90 #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) |
|
91 |
|
92 namespace boost |
|
93 { |
|
94 |
|
95 namespace detail |
|
96 { |
|
97 |
|
98 extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement( long volatile * ); |
|
99 extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement( long volatile * ); |
|
100 extern "C" __declspec(dllimport) long __stdcall InterlockedCompareExchange( long volatile *, long, long ); |
|
101 extern "C" __declspec(dllimport) long __stdcall InterlockedExchange( long volatile *, long ); |
|
102 extern "C" __declspec(dllimport) long __stdcall InterlockedExchangeAdd( long volatile *, long ); |
|
103 |
|
104 } // namespace detail |
|
105 |
|
106 } // namespace boost |
|
107 |
|
108 # define BOOST_INTERLOCKED_INCREMENT ::boost::detail::InterlockedIncrement |
|
109 # define BOOST_INTERLOCKED_DECREMENT ::boost::detail::InterlockedDecrement |
|
110 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE ::boost::detail::InterlockedCompareExchange |
|
111 # define BOOST_INTERLOCKED_EXCHANGE ::boost::detail::InterlockedExchange |
|
112 # define BOOST_INTERLOCKED_EXCHANGE_ADD ::boost::detail::InterlockedExchangeAdd |
|
113 |
|
114 # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \ |
|
115 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare))) |
|
116 # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \ |
|
117 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange))) |
|
118 |
|
119 #else |
|
120 |
|
121 # error "Interlocked intrinsics not available" |
|
122 |
|
123 #endif |
|
124 |
|
125 #endif // #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED |