8#ifndef INCLUDED_BSLS_ATOMICOPERATIONS_X86_WIN_MSVC
9#define INCLUDED_BSLS_ATOMICOPERATIONS_X86_WIN_MSVC
54#include <bsls_atomicoperations_default.h>
58#if defined(BSLS_PLATFORM_CPU_X86) && defined(BSLS_PLATFORM_CMP_MSVC)
80struct AtomicOperations_X86_WIN_MSVC;
81typedef AtomicOperations_X86_WIN_MSVC AtomicOperations_Imp;
88struct Atomic_TypeTraits<AtomicOperations_X86_WIN_MSVC>
99 volatile Types::Int64 d_value;
105 volatile
unsigned int d_value;
111 volatile Types::Uint64 d_value;
117 void * volatile d_value;
125struct AtomicOperations_X86_WIN_MSVC
126 : AtomicOperations_Default32<AtomicOperations_X86_WIN_MSVC>
128 typedef Atomic_TypeTraits<AtomicOperations_X86_WIN_MSVC> AtomicTypes;
132 static int getInt(
const AtomicTypes::Int *atomicInt);
134 static int getIntAcquire(
const AtomicTypes::Int *atomicInt);
136 static void setInt(AtomicTypes::Int *atomicInt,
int value);
138 static void setIntRelease(AtomicTypes::Int *atomicInt,
int value);
140 static int swapInt(AtomicTypes::Int *atomicInt,
int swapValue);
142 static int testAndSwapInt(AtomicTypes::Int *atomicInt,
146 static int addIntNv(AtomicTypes::Int *atomicInt,
int value);
150 static Types::Int64 getInt64(
const AtomicTypes::Int64 *atomicInt);
152 static void setInt64(AtomicTypes::Int64 *atomicInt, Types::Int64 value);
154 static Types::Int64 swapInt64(AtomicTypes::Int64 *atomicInt,
155 Types::Int64 swapValue);
157 static Types::Int64 testAndSwapInt64(AtomicTypes::Int64 *atomicInt,
158 Types::Int64 compareValue,
159 Types::Int64 swapValue);
161 static Types::Int64 addInt64Nv(AtomicTypes::Int64 *atomicInt,
174#define BSLS_ATOMIC_FENCE() \
175 __asm lock add dword ptr [esp], 0
178int AtomicOperations_X86_WIN_MSVC::
179 getInt(
const AtomicTypes::Int *atomicInt)
182 return atomicInt->d_value;
186int AtomicOperations_X86_WIN_MSVC::
187 getIntAcquire(
const AtomicTypes::Int *atomicInt)
189 return atomicInt->d_value;
193void AtomicOperations_X86_WIN_MSVC::
194 setInt(AtomicTypes::Int *atomicInt,
int value)
196 atomicInt->d_value = value;
201void AtomicOperations_X86_WIN_MSVC::
202 setIntRelease(AtomicTypes::Int *atomicInt,
int value)
204 atomicInt->d_value = value;
208int AtomicOperations_X86_WIN_MSVC::
209 swapInt(AtomicTypes::Int *atomicInt,
int swapValue)
211 return _InterlockedExchange(
212 reinterpret_cast<long volatile *
>(&atomicInt->d_value),
217int AtomicOperations_X86_WIN_MSVC::
218 testAndSwapInt(AtomicTypes::Int *atomicInt,
222 return _InterlockedCompareExchange(
223 reinterpret_cast<long volatile *
>(&atomicInt->d_value),
229int AtomicOperations_X86_WIN_MSVC::
230 addIntNv(AtomicTypes::Int *atomicInt,
int value)
232 return static_cast<unsigned>(_InterlockedExchangeAdd(
233 reinterpret_cast<long volatile *
>(
234 &atomicInt->d_value),
242Types::Int64 AtomicOperations_X86_WIN_MSVC::
243 getInt64(
const AtomicTypes::Int64 *atomicInt)
245 return _InterlockedCompareExchange64(
246 const_cast<Types::Int64
volatile *
>(&atomicInt->d_value),
252void AtomicOperations_X86_WIN_MSVC::
253 setInt64(AtomicTypes::Int64 *atomicInt, Types::Int64 value)
255 swapInt64(atomicInt, value);
259Types::Int64 AtomicOperations_X86_WIN_MSVC::
260 swapInt64(AtomicTypes::Int64 *atomicInt,
261 Types::Int64 swapValue)
263 Types::Int64 actual = atomicInt->d_value;
264 Types::Int64 expected;
269 actual = testAndSwapInt64(atomicInt, expected, swapValue);
270 }
while (actual != expected);
276Types::Int64 AtomicOperations_X86_WIN_MSVC::
277 testAndSwapInt64(AtomicTypes::Int64 *atomicInt,
278 Types::Int64 compareValue,
279 Types::Int64 swapValue)
281 return _InterlockedCompareExchange64(
288Types::Int64 AtomicOperations_X86_WIN_MSVC::
289 addInt64Nv(AtomicTypes::Int64 *atomicInt,
292 Types::Int64 actual = atomicInt->d_value;
293 Types::Int64 expected;
298 actual = testAndSwapInt64(atomicInt, expected, expected + value);
299 }
while (actual != expected);
301 return expected + value;
304#undef BSLS_ATOMIC_FENCE
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlt_iso8601util.h:691