blob: 4ad8271771b20117dacf65001e377495a3fab3d9 [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001#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
Jeff Thompson2277ce52013-08-01 17:34:11 -070020#include <ndnboost/config.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070021
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#if _WIN32_WCE >= 0x600
37
38extern "C" long __cdecl _InterlockedIncrement( long volatile * );
39extern "C" long __cdecl _InterlockedDecrement( long volatile * );
40extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long );
41extern "C" long __cdecl _InterlockedExchange( long volatile *, long );
42extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, 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#else
51// under Windows CE we still have old-style Interlocked* functions
52
53extern "C" long __cdecl InterlockedIncrement( long* );
54extern "C" long __cdecl InterlockedDecrement( long* );
55extern "C" long __cdecl InterlockedCompareExchange( long*, long, long );
56extern "C" long __cdecl InterlockedExchange( long*, long );
57extern "C" long __cdecl InterlockedExchangeAdd( long*, long );
58
59# define BOOST_INTERLOCKED_INCREMENT InterlockedIncrement
60# define BOOST_INTERLOCKED_DECREMENT InterlockedDecrement
61# define BOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange
62# define BOOST_INTERLOCKED_EXCHANGE InterlockedExchange
63# define BOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd
64
65#endif
66
67# define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
68 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long*)(dest),(long)(exchange),(long)(compare)))
69# define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
70 ((void*)BOOST_INTERLOCKED_EXCHANGE((long*)(dest),(long)(exchange)))
71
72#elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN )
73
74#if defined( BOOST_MSVC ) && BOOST_MSVC >= 1600
75
76#include <intrin.h>
77
78#elif defined( __CLRCALL_PURE_OR_CDECL )
79
80extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedIncrement( long volatile * );
81extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedDecrement( long volatile * );
82extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange( long volatile *, long, long );
83extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchange( long volatile *, long );
84extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchangeAdd( long volatile *, long );
85
86#else
87
88extern "C" long __cdecl _InterlockedIncrement( long volatile * );
89extern "C" long __cdecl _InterlockedDecrement( long volatile * );
90extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long );
91extern "C" long __cdecl _InterlockedExchange( long volatile *, long );
92extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long );
93
94#endif
95
96# pragma intrinsic( _InterlockedIncrement )
97# pragma intrinsic( _InterlockedDecrement )
98# pragma intrinsic( _InterlockedCompareExchange )
99# pragma intrinsic( _InterlockedExchange )
100# pragma intrinsic( _InterlockedExchangeAdd )
101
102# if defined(_M_IA64) || defined(_M_AMD64)
103
104extern "C" void* __cdecl _InterlockedCompareExchangePointer( void* volatile *, void*, void* );
105extern "C" void* __cdecl _InterlockedExchangePointer( void* volatile *, void* );
106
107# pragma intrinsic( _InterlockedCompareExchangePointer )
108# pragma intrinsic( _InterlockedExchangePointer )
109
110# define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER _InterlockedCompareExchangePointer
111# define BOOST_INTERLOCKED_EXCHANGE_POINTER _InterlockedExchangePointer
112
113# else
114
115# define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
116 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
117# define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
118 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
119
120# endif
121
122# define BOOST_INTERLOCKED_INCREMENT _InterlockedIncrement
123# define BOOST_INTERLOCKED_DECREMENT _InterlockedDecrement
124# define BOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange
125# define BOOST_INTERLOCKED_EXCHANGE _InterlockedExchange
126# define BOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd
127
128#elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
129
130#if defined(__MINGW64__)
131#define BOOST_INTERLOCKED_IMPORT
132#else
133#define BOOST_INTERLOCKED_IMPORT __declspec(dllimport)
134#endif
135
136
137namespace ndnboost
138{
139
140namespace detail
141{
142
143extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedIncrement( long volatile * );
144extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedDecrement( long volatile * );
145extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedCompareExchange( long volatile *, long, long );
146extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedExchange( long volatile *, long );
147extern "C" BOOST_INTERLOCKED_IMPORT long __stdcall InterlockedExchangeAdd( long volatile *, long );
148
149# if defined(_M_IA64) || defined(_M_AMD64)
150extern "C" BOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedCompareExchangePointer( void* volatile *, void*, void* );
151extern "C" BOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedExchangePointer( void* volatile *, void* );
152# endif
153
154} // namespace detail
155
156} // namespace ndnboost
157
158# define BOOST_INTERLOCKED_INCREMENT ::ndnboost::detail::InterlockedIncrement
159# define BOOST_INTERLOCKED_DECREMENT ::ndnboost::detail::InterlockedDecrement
160# define BOOST_INTERLOCKED_COMPARE_EXCHANGE ::ndnboost::detail::InterlockedCompareExchange
161# define BOOST_INTERLOCKED_EXCHANGE ::ndnboost::detail::InterlockedExchange
162# define BOOST_INTERLOCKED_EXCHANGE_ADD ::ndnboost::detail::InterlockedExchangeAdd
163
164# if defined(_M_IA64) || defined(_M_AMD64)
165# define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER ::ndnboost::detail::InterlockedCompareExchangePointer
166# define BOOST_INTERLOCKED_EXCHANGE_POINTER ::ndnboost::detail::InterlockedExchangePointer
167# else
168# define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
169 ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare)))
170# define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
171 ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange)))
172# endif
173
174#else
175
176# error "Interlocked intrinsics not available"
177
178#endif
179
180#endif // #ifndef BOOST_DETAIL_INTERLOCKED_HPP_INCLUDED