Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 1 | #ifndef NDNBOOST_DETAIL_INTERLOCKED_HPP_INCLUDED |
| 2 | #define NDNBOOST_DETAIL_INTERLOCKED_HPP_INCLUDED |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 3 | |
| 4 | // MS compatible compilers support #pragma once |
| 5 | |
| 6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 7 | # pragma once |
| 8 | #endif |
| 9 | |
| 10 | // |
Jeff Thompson | 9939dcd | 2013-10-15 15:12:24 -0700 | [diff] [blame] | 11 | // ndnboost/detail/interlocked.hpp |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 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 Thompson | 2277ce5 | 2013-08-01 17:34:11 -0700 | [diff] [blame] | 20 | #include <ndnboost/config.hpp> |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 21 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 22 | #if defined( NDNBOOST_USE_WINDOWS_H ) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 23 | |
| 24 | # include <windows.h> |
| 25 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 26 | # define NDNBOOST_INTERLOCKED_INCREMENT InterlockedIncrement |
| 27 | # define NDNBOOST_INTERLOCKED_DECREMENT InterlockedDecrement |
| 28 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange |
| 29 | # define NDNBOOST_INTERLOCKED_EXCHANGE InterlockedExchange |
| 30 | # define NDNBOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd |
| 31 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER InterlockedCompareExchangePointer |
| 32 | # define NDNBOOST_INTERLOCKED_EXCHANGE_POINTER InterlockedExchangePointer |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 33 | |
| 34 | #elif defined(_WIN32_WCE) |
| 35 | |
| 36 | #if _WIN32_WCE >= 0x600 |
| 37 | |
| 38 | extern "C" long __cdecl _InterlockedIncrement( long volatile * ); |
| 39 | extern "C" long __cdecl _InterlockedDecrement( long volatile * ); |
| 40 | extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long ); |
| 41 | extern "C" long __cdecl _InterlockedExchange( long volatile *, long ); |
| 42 | extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long ); |
| 43 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 44 | # define NDNBOOST_INTERLOCKED_INCREMENT _InterlockedIncrement |
| 45 | # define NDNBOOST_INTERLOCKED_DECREMENT _InterlockedDecrement |
| 46 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange |
| 47 | # define NDNBOOST_INTERLOCKED_EXCHANGE _InterlockedExchange |
| 48 | # define NDNBOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 49 | |
| 50 | #else |
| 51 | // under Windows CE we still have old-style Interlocked* functions |
| 52 | |
| 53 | extern "C" long __cdecl InterlockedIncrement( long* ); |
| 54 | extern "C" long __cdecl InterlockedDecrement( long* ); |
| 55 | extern "C" long __cdecl InterlockedCompareExchange( long*, long, long ); |
| 56 | extern "C" long __cdecl InterlockedExchange( long*, long ); |
| 57 | extern "C" long __cdecl InterlockedExchangeAdd( long*, long ); |
| 58 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 59 | # define NDNBOOST_INTERLOCKED_INCREMENT InterlockedIncrement |
| 60 | # define NDNBOOST_INTERLOCKED_DECREMENT InterlockedDecrement |
| 61 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange |
| 62 | # define NDNBOOST_INTERLOCKED_EXCHANGE InterlockedExchange |
| 63 | # define NDNBOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 64 | |
| 65 | #endif |
| 66 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 67 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \ |
| 68 | ((void*)NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE((long*)(dest),(long)(exchange),(long)(compare))) |
| 69 | # define NDNBOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \ |
| 70 | ((void*)NDNBOOST_INTERLOCKED_EXCHANGE((long*)(dest),(long)(exchange))) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 71 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 72 | #elif defined( NDNBOOST_MSVC ) || defined( NDNBOOST_INTEL_WIN ) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 73 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 74 | #if defined( NDNBOOST_MSVC ) && NDNBOOST_MSVC >= 1600 |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 75 | |
| 76 | #include <intrin.h> |
| 77 | |
| 78 | #elif defined( __CLRCALL_PURE_OR_CDECL ) |
| 79 | |
| 80 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedIncrement( long volatile * ); |
| 81 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedDecrement( long volatile * ); |
| 82 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange( long volatile *, long, long ); |
| 83 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchange( long volatile *, long ); |
| 84 | extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedExchangeAdd( long volatile *, long ); |
| 85 | |
| 86 | #else |
| 87 | |
| 88 | extern "C" long __cdecl _InterlockedIncrement( long volatile * ); |
| 89 | extern "C" long __cdecl _InterlockedDecrement( long volatile * ); |
| 90 | extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long ); |
| 91 | extern "C" long __cdecl _InterlockedExchange( long volatile *, long ); |
| 92 | extern "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 | |
| 104 | extern "C" void* __cdecl _InterlockedCompareExchangePointer( void* volatile *, void*, void* ); |
| 105 | extern "C" void* __cdecl _InterlockedExchangePointer( void* volatile *, void* ); |
| 106 | |
| 107 | # pragma intrinsic( _InterlockedCompareExchangePointer ) |
| 108 | # pragma intrinsic( _InterlockedExchangePointer ) |
| 109 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 110 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER _InterlockedCompareExchangePointer |
| 111 | # define NDNBOOST_INTERLOCKED_EXCHANGE_POINTER _InterlockedExchangePointer |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 112 | |
| 113 | # else |
| 114 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 115 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \ |
| 116 | ((void*)NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare))) |
| 117 | # define NDNBOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \ |
| 118 | ((void*)NDNBOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange))) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 119 | |
| 120 | # endif |
| 121 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 122 | # define NDNBOOST_INTERLOCKED_INCREMENT _InterlockedIncrement |
| 123 | # define NDNBOOST_INTERLOCKED_DECREMENT _InterlockedDecrement |
| 124 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange |
| 125 | # define NDNBOOST_INTERLOCKED_EXCHANGE _InterlockedExchange |
| 126 | # define NDNBOOST_INTERLOCKED_EXCHANGE_ADD _InterlockedExchangeAdd |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 127 | |
| 128 | #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) |
| 129 | |
| 130 | #if defined(__MINGW64__) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 131 | #define NDNBOOST_INTERLOCKED_IMPORT |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 132 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 133 | #define NDNBOOST_INTERLOCKED_IMPORT __declspec(dllimport) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 134 | #endif |
| 135 | |
| 136 | |
| 137 | namespace ndnboost |
| 138 | { |
| 139 | |
| 140 | namespace detail |
| 141 | { |
| 142 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 143 | extern "C" NDNBOOST_INTERLOCKED_IMPORT long __stdcall InterlockedIncrement( long volatile * ); |
| 144 | extern "C" NDNBOOST_INTERLOCKED_IMPORT long __stdcall InterlockedDecrement( long volatile * ); |
| 145 | extern "C" NDNBOOST_INTERLOCKED_IMPORT long __stdcall InterlockedCompareExchange( long volatile *, long, long ); |
| 146 | extern "C" NDNBOOST_INTERLOCKED_IMPORT long __stdcall InterlockedExchange( long volatile *, long ); |
| 147 | extern "C" NDNBOOST_INTERLOCKED_IMPORT long __stdcall InterlockedExchangeAdd( long volatile *, long ); |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 148 | |
| 149 | # if defined(_M_IA64) || defined(_M_AMD64) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 150 | extern "C" NDNBOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedCompareExchangePointer( void* volatile *, void*, void* ); |
| 151 | extern "C" NDNBOOST_INTERLOCKED_IMPORT void* __stdcall InterlockedExchangePointer( void* volatile *, void* ); |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 152 | # endif |
| 153 | |
| 154 | } // namespace detail |
| 155 | |
| 156 | } // namespace ndnboost |
| 157 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 158 | # define NDNBOOST_INTERLOCKED_INCREMENT ::ndnboost::detail::InterlockedIncrement |
| 159 | # define NDNBOOST_INTERLOCKED_DECREMENT ::ndnboost::detail::InterlockedDecrement |
| 160 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE ::ndnboost::detail::InterlockedCompareExchange |
| 161 | # define NDNBOOST_INTERLOCKED_EXCHANGE ::ndnboost::detail::InterlockedExchange |
| 162 | # define NDNBOOST_INTERLOCKED_EXCHANGE_ADD ::ndnboost::detail::InterlockedExchangeAdd |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 163 | |
| 164 | # if defined(_M_IA64) || defined(_M_AMD64) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 165 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER ::ndnboost::detail::InterlockedCompareExchangePointer |
| 166 | # define NDNBOOST_INTERLOCKED_EXCHANGE_POINTER ::ndnboost::detail::InterlockedExchangePointer |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 167 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 168 | # define NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \ |
| 169 | ((void*)NDNBOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare))) |
| 170 | # define NDNBOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \ |
| 171 | ((void*)NDNBOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange))) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 172 | # endif |
| 173 | |
| 174 | #else |
| 175 | |
| 176 | # error "Interlocked intrinsics not available" |
| 177 | |
| 178 | #endif |
| 179 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 180 | #endif // #ifndef NDNBOOST_DETAIL_INTERLOCKED_HPP_INCLUDED |