5#include "GenericPlatform/GenericPlatformAtomics.h"
6#include "Windows/WindowsSystemIncludes.h"
10
11
15 static_assert(
sizeof(int8) ==
sizeof(
char) &&
alignof(int8) ==
alignof(
char),
"int8 must be compatible with char");
16 static_assert(
sizeof(int16) ==
sizeof(
short) &&
alignof(int16) ==
alignof(
short),
"int16 must be compatible with short");
17 static_assert(
sizeof(int32) ==
sizeof(
long) &&
alignof(int32) ==
alignof(
long),
"int32 must be compatible with long");
18 static_assert(
sizeof(int64) ==
sizeof(
long long) &&
alignof(int64) ==
alignof(
long long),
"int64 must be compatible with long long");
22 return (int8)::_InterlockedExchangeAdd8((
char*)Value, 1) + 1;
27 return (int16)::_InterlockedIncrement16((
short*)Value);
32 return (int32)::_InterlockedIncrement((
long*)Value);
38 return (int64)::_InterlockedIncrement64((
long long*)Value);
43 int64 OldValue = *Value;
44 if (_InterlockedCompareExchange64(Value, OldValue + 1, OldValue) == OldValue)
54 return (int8)::_InterlockedExchangeAdd8((
char*)Value, -1) - 1;
59 return (int16)::_InterlockedDecrement16((
short*)Value);
64 return (int32)::_InterlockedDecrement((
long*)Value);
70 return (int64)::_InterlockedDecrement64((
long long*)Value);
75 int64 OldValue = *Value;
76 if (_InterlockedCompareExchange64(Value, OldValue - 1, OldValue) == OldValue)
86 return (int8)::_InterlockedExchangeAdd8((
char*)Value, (
char)Amount);
91 return (int16)::_InterlockedExchangeAdd16((
short*)Value, (
short)Amount);
96 return (int32)::_InterlockedExchangeAdd((
long*)Value, (
long)Amount);
102 return (int64)::_InterlockedExchangeAdd64((int64*)Value, (int64)Amount);
107 int64 OldValue = *Value;
108 if (_InterlockedCompareExchange64(Value, OldValue + Amount, OldValue) == OldValue)
118 return (int8)::_InterlockedExchange8((
char*)Value, (
char)Exchange);
123 return (int16)::_InterlockedExchange16((
short*)Value, (
short)Exchange);
128 return (int32)::_InterlockedExchange((
long*)Value, (
long)Exchange);
134 return (int64)::_InterlockedExchange64((
long long*)Value, (
long long)Exchange);
139 int64 OldValue = *Value;
140 if (_InterlockedCompareExchange64(Value, Exchange, OldValue) == OldValue)
151 if (IsAligned(Dest,
alignof(
void*)) ==
false)
153 HandleAtomicsFailure(TEXT(
"InterlockedExchangePointer requires Dest pointer to be aligned to %d bytes"), (
int)
alignof(
void*));
157 return ::_InterlockedExchangePointer(Dest, Exchange);
162 return (int8)::_InterlockedCompareExchange8((
char*)Dest, (
char)Exchange, (
char)Comparand);
167 return (int16)::_InterlockedCompareExchange16((
short*)Dest, (
short)Exchange, (
short)Comparand);
172 return (int32)::_InterlockedCompareExchange((
long*)Dest, (
long)Exchange, (
long)Comparand);
178 if (IsAligned(Dest,
alignof(int64)) ==
false)
180 HandleAtomicsFailure(TEXT(
"InterlockedCompareExchange int64 requires Dest pointer to be aligned to %d bytes"), (
int)
alignof(int64));
184 return (int64)::_InterlockedCompareExchange64(Dest, Exchange, Comparand);
189 return (int8)::_InterlockedAnd8((
volatile char*)Value, (
char)AndValue);
194 return (int16)::_InterlockedAnd16((
volatile short*)Value, (
short)AndValue);
199 return (int32)::_InterlockedAnd((
volatile long*)Value, (
long)AndValue);
205 return (int64)::_InterlockedAnd64((
volatile long long*)Value, (
long long)AndValue);
210 const int64 OldValue = *Value;
211 if (_InterlockedCompareExchange64(Value, OldValue & AndValue, OldValue) == OldValue)
221 return (int8)::_InterlockedOr8((
volatile char*)Value, (
char)OrValue);
226 return (int16)::_InterlockedOr16((
volatile short*)Value, (
short)OrValue);
231 return (int32)::_InterlockedOr((
volatile long*)Value, (
long)OrValue);
237 return (int64)::_InterlockedOr64((
volatile long long*)Value, (
long long)OrValue);
242 const int64 OldValue = *Value;
243 if (_InterlockedCompareExchange64(Value, OldValue | OrValue, OldValue) == OldValue)
253 return (int8)::_InterlockedXor8((
volatile char*)Value, (
char)XorValue);
258 return (int16)::_InterlockedXor16((
volatile short*)Value, (
short)XorValue);
263 return (int32)::_InterlockedXor((
volatile long*)Value, (int32)XorValue);
269 return (int64)::_InterlockedXor64((
volatile long long*)Value, (
long long)XorValue);
274 const int64 OldValue = *Value;
275 if (_InterlockedCompareExchange64(Value, OldValue ^ XorValue, OldValue) == OldValue)
323 return InterlockedCompareExchange2((
volatile int64*)Src, 0, 0);
367 InterlockedExchange(Src, Val);
371 UE_DEPRECATED(4.19,
"AtomicRead64 has been deprecated, please use AtomicRead's overload instead")
378
379
380
381
382
383
384
385
386
390#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
404
405
420 if (IsAligned(Dest,
alignof(
void*)) ==
false)
422 HandleAtomicsFailure(TEXT(
"InterlockedCompareExchangePointer requires Dest pointer to be aligned to %d bytes"), (
int)
alignof(
void*));
426 return ::_InterlockedCompareExchangePointer(Dest, Exchange, Comparand);
430
431
432
440
441
442
443
444
445
#define UE_BUILD_SHIPPING
#define UE_DEPRECATED(Version, Message)
#define WINDOWS_PF_COMPARE_EXCHANGE128
MINIMAL_WINDOWS_API BOOL WINAPI IsProcessorFeaturePresent(DWORD ProcessorFeature)