UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GenericPlatformAtomics.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6
7
9struct MS_ALIGN(16) FInt128
10{
12 int64 Low;
14 int64 High;
15}
17
18
26{
27#if 0 // can never use these since the actual implementation would have to be in a derived class as we are not using virtuals
28 // provided here for reference
32 static FORCEINLINE int32 InterlockedIncrement(volatile int32* Value)
33 {
35 do
36 {
37 RetVal = *Value;
39 return RetVal + 1;
40 }
41
42#if PLATFORM_64BITS
46 static FORCEINLINE int64 InterlockedIncrement(volatile int64* Value)
47 {
49 do
50 {
51 RetVal = *Value;
53 return RetVal + 1;
54 }
55#endif
56
60 static FORCEINLINE int32 InterlockedDecrement(volatile int32* Value)
61 {
63 do
64 {
65 RetVal = *Value;
67 return RetVal - 1;
68 }
69
70#if PLATFORM_64BITS
74 static FORCEINLINE int64 InterlockedDecrement(volatile int64* Value)
75 {
77 do
78 {
79 RetVal = *Value;
81 return RetVal - 1;
82 }
83#endif
84
89 static FORCEINLINE int32 InterlockedAdd(volatile int32* Value,int32 Amount)
90 {
92 do
93 {
94 RetVal = *Value;
95 } while (InterlockedCompareExchange((int32*)Value, RetVal + Amount, RetVal) != RetVal);
96 return RetVal;
97 }
98
99#if PLATFORM_64BITS
104 static FORCEINLINE int64 InterlockedAdd(volatile int64* Value, int64 Amount)
105 {
107 do
108 {
109 RetVal = *Value;
110 } while (InterlockedCompareExchange((int64*)Value, RetVal + Amount, RetVal) != RetVal);
111 return RetVal;
112 }
113#endif
114
118 static FORCEINLINE int32 InterlockedExchange(volatile int32* Value,int32 Exchange)
119 {
121 do
122 {
123 RetVal = *Value;
125 return RetVal;
126 }
127
128#if PLATFORM_64BITS
132 static FORCEINLINE int64 InterlockedExchange (volatile int64* Value, int64 Exchange)
133 {
135 do
136 {
137 RetVal = *Value;
139 return RetVal;
140 }
141#endif
142
146 static FORCEINLINE void* InterlockedExchangePtr( void*volatile* Dest, void* Exchange )
147 {
148#if PLATFORM_64BITS
149 #error must implement
150#else
151 InterlockedExchange((int32*)Dest, (int32)Exchange);
152#endif
153 }
154
160 {
161 #error must implement
162 }
163
169 {
170 #error must implement
171 }
172
178 {
179 #error must implement
180 }
181
188 {
189 #error must implement
190 }
191
196 static FORCEINLINE int32 InterlockedAnd(volatile int32* Value, const int32 AndValue)
197 {
199 do
200 {
201 RetVal = *Value;
203 return RetVal;
204 }
205
210 static FORCEINLINE int32 InterlockedOr(volatile int32* Value, const int32 OrValue)
211 {
213 do
214 {
215 RetVal = *Value;
217 return RetVal;
218 }
219
224 static FORCEINLINE int32 InterlockedXor(volatile int32* Value, const int32 XorValue)
225 {
227 do
228 {
229 RetVal = *Value;
231 return RetVal;
232 }
233
237 static FORCEINLINE int8 AtomicRead(volatile const int8* Src)
238 {
239 return InterlockedCompareExchange((volatile int8*)Src, 0, 0);
240 }
241
245 static FORCEINLINE int16 AtomicRead(volatile const int16* Src)
246 {
247 return InterlockedCompareExchange((volatile int16*)Src, 0, 0);
248 }
249
253 static FORCEINLINE int32 AtomicRead(volatile const int32* Src)
254 {
255 return InterlockedCompareExchange((volatile int32*)Src, 0, 0);
256 }
257
261 static FORCEINLINE int64 AtomicRead(volatile const int64* Src)
262 {
263 return InterlockedCompareExchange((volatile int64*)Src, 0, 0);
264 }
265
270 static FORCEINLINE void* InterlockedCompareExchangePointer(void*volatile* Dest,void* Exchange,void* Comperand)
271 {
272#if PLATFORM_64BITS
273 #error must implement
274#else
276#endif
277 }
278
279#if PLATFORM_HAS_128BIT_ATOMICS
289 {
290 #error Must implement
291 }
292
296 static FORCEINLINE void AtomicRead128(const volatile FInt128* Src, FInt128* OutResult)
297 {
299 Zero.High = 0;
300 Zero.Low = 0;
301 *OutResult = Zero;
303 }
304#endif // PLATFORM_HAS_128BIT_ATOMICS
305
306#endif // 0
307
308
314 {
315 return false;
316 }
317
318protected:
326 static inline bool IsAligned( const volatile void* Ptr, const uint32 Alignment = sizeof(void*) )
327 {
328 return !(PTRINT(Ptr) & (Alignment - 1));
329 }
330};
331
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define GCC_ALIGN(n)
Definition AndroidPlatform.h:163
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
FPlatformTypes::PTRINT PTRINT
A signed integer the same size as a pointer.
Definition Platform.h:1148
#define MS_ALIGN(n)
Definition Platform.h:916
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
bool InterlockedCompareExchange(const FIndexedPointer &Exchange, const FIndexedPointer &Comparand)
Definition LockFreeList.h:65
void AtomicRead(const FIndexedPointer &Other)
Definition LockFreeList.h:58
UE_REWRITE constexpr void Exchange(T &A, T &B)
Definition UnrealTemplate.h:627
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition GenericPlatformAtomics.h:26
static FORCEINLINE bool CanUseCompareExchange128()
Definition GenericPlatformAtomics.h:313
static bool IsAligned(const volatile void *Ptr, const uint32 Alignment=sizeof(void *))
Definition GenericPlatformAtomics.h:326