5#include "Containers/Array.h"
24 #define checkLockFreePointerList checkSlow
27 #pragma warning(disable : 4706)
29 #define checkLockFreePointerList(x) ((x)||((*(char*)3) = 0))
32#if !UE_BUILD_SHIPPING && !UE_BUILD_TEST
55#define MAX_LOCK_FREE_LINKS_AS_BITS (26)
56#define MAX_LOCK_FREE_LINKS (1 << 26)
58template<
class T,
unsigned int MaxTotalItems,
unsigned int ItemsPerPage>
111 if (FPlatformAtomics::InterlockedCompareExchangePointer((
void**)&Pages[
BlockIndex],
NewBlock,
nullptr) !=
nullptr)
130#define MAX_TagBitsValue (uint64(1) << (64 - MAX_LOCK_FREE_LINKS_AS_BITS))
144 Ptrs.store(0, std::memory_order_relaxed);
182 template<u
int64 TABAInc>
188 template<u
int64 TABAInc>
198 Ptrs.store(
Other.Ptrs.load(std::memory_order_acquire), std::memory_order_relaxed);
206 return Ptrs.compare_exchange_strong(Expected,
Exchange.Ptrs.load(std::memory_order_relaxed), std::memory_order_acq_rel, std::memory_order_relaxed);
211 return Ptrs.load(std::memory_order_relaxed) ==
Other.Ptrs.load(std::memory_order_relaxed);
215 return Ptrs.load(std::memory_order_relaxed) !=
Other.Ptrs.load(std::memory_order_relaxed);
219 std::atomic<uint64> Ptrs;
260template<
int TPaddingForCacheContention, u
int64 TABAInc = 1>
275 static_assert((
TABAInc & (
TABAInc - 1)) == 0,
"must be power of two");
303 static_assert(
TABAInc > 1,
"method should not be used for lists without state");
343 NewHead.SetPtr(
ItemP->SingleNext.load(std::memory_order_relaxed));
346 ItemP->SingleNext.store(0, std::memory_order_relaxed);
378 static_assert(
TABAInc > 1,
"method should not be used for lists without state");
413template<
class T,
int TPaddingForCacheContention, u
int64 TABAInc = 1>
475 TLinkPtr Item = RootList.
Pop();
485 template <
typename ContainerType>
494 Links =
LinksP->SingleNext.load(std::memory_order_relaxed);
499 template <
typename FunctorType>
508 Links =
LinksP->SingleNext.load(std::memory_order_relaxed);
513 template <
typename ContainerType>
522 Links =
LinksP->SingleNext.load(std::memory_order_relaxed);
542template<
class T,
int TPaddingForCacheContention, u
int64 TABAInc = 1>
556 static_assert(
TABAInc <= 65536,
"risk of ABA problem");
557 static_assert((
TABAInc & (
TABAInc - 1)) == 0,
"must be power of two");
662 template <
typename ContainerType>
665 while (T* Item =
Pop())
687template<
class T,
int TPaddingForCacheContention,
int NumPriorities>
764 T *Result = PriorityQueues[
Index].Pop();
839template<
class T,
int TPaddingForCacheContention>
868 template <
typename ContainerType>
877 template <
typename FunctorType>
902template<
class T,
int TPaddingForCacheContention>
908template<
class T,
int TPaddingForCacheContention>
937 template <
typename ContainerType>
957template<
class T,
int TPaddingForCacheContention>
986 template <
typename ContainerType>
constexpr bool IsAligned(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:50
#define check(expr)
Definition AssertionMacros.h:314
#define UE_NONCOPYABLE(TypeName)
Definition CoreMiscDefines.h:457
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
CORE_API void * LockFreeAllocLinks(SIZE_T AllocSize)
Definition LockFreeList.cpp:64
UE_FORCEINLINE_HINT uint32 GetPtr() const
Definition LockFreeList.h:15
UE_FORCEINLINE_HINT uint64 GetCounterAndState() const
Definition LockFreeList.h:25
void SetAll(uint32 Ptr, uint64 CounterAndState)
Definition LockFreeList.h:9
CORE_API void LockFreeTagCounterHasOverflowed()
Definition LockFreeList.cpp:41
#define MAX_TagBitsValue
Definition LockFreeList.h:130
#define MAX_LOCK_FREE_LINKS
Definition LockFreeList.h:56
#define MAX_LOCK_FREE_LINKS_AS_BITS
Definition LockFreeList.h:55
UE_FORCEINLINE_HINT void SetCounterAndState(uint64 To)
Definition LockFreeList.h:30
CORE_API void LockFreeLinksExhausted(uint32 TotalNum)
Definition LockFreeList.cpp:47
CORE_API int32 GTestCriticalStalls
Definition LockFreeList.cpp:31
struct FIndexedLockFreeLink GCC_ALIGN
#define checkLockFreePointerList
Definition LockFreeList.h:24
CORE_API void DoTestCriticalStall()
Definition LockFreeList.cpp:18
CORE_API void LockFreeFreeLinks(SIZE_T AllocSize, void *Ptr)
Definition LockFreeList.cpp:69
void TestCriticalStall()
Definition LockFreeList.h:37
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
UE_REWRITE constexpr void Exchange(T &A, T &B)
Definition UnrealTemplate.h:627
int BlockIndex
Definition binka_ue_decode_test.cpp:38
Definition LockFreeList.h:544
~FLockFreePointerFIFOBase()
Definition LockFreeList.h:566
FLockFreePointerFIFOBase()
Definition LockFreeList.h:552
T * Pop()
Definition LockFreeList.h:617
void Push(T *InPayload)
Definition LockFreeList.h:572
void PopAll(ContainerType &OutContainer)
Definition LockFreeList.h:663
bool IsEmpty() const
Definition LockFreeList.h:672
Definition LockFreeList.h:415
UE_FORCEINLINE_HINT uint64 GetState() const
Definition LockFreeList.h:532
~FLockFreePointerListLIFOBase()
Definition LockFreeList.h:425
bool PushIf(T *InPayload, TFunctionRef< bool(uint64)> OkToPush)
Definition LockFreeList.h:443
FLockFreePointerListLIFOBase()=default
T * Pop()
Definition LockFreeList.h:473
UE_FORCEINLINE_HINT bool IsEmpty() const
Definition LockFreeList.h:527
void PopAllAndChangeState(ContainerType &OutContainer, TFunctionRef< uint64(uint64)> StateChange)
Definition LockFreeList.h:514
void Reset()
Definition LockFreeList.h:430
void PopAllAndApply(FunctorType InFunctor)
Definition LockFreeList.h:500
void Push(T *InPayload)
Definition LockFreeList.h:436
void PopAll(ContainerType &OutContainer)
Definition LockFreeList.h:486
Definition LockFreeList.h:262
UE_FORCEINLINE_HINT bool IsEmpty() const
Definition LockFreeList.h:397
TLinkPtr PopAllAndChangeState(TFunctionRef< uint64(uint64)> StateChange)
Definition LockFreeList.h:376
TLinkPtr PopAll()
Definition LockFreeList.h:353
bool PushIf(TFunctionRef< TLinkPtr(uint64)> AllocateIfOkToPush)
Definition LockFreeList.h:301
uint64 GetState() const
Definition LockFreeList.h:402
void Push(TLinkPtr Item)
Definition LockFreeList.h:284
void Reset()
Definition LockFreeList.h:279
TLinkPtr Pop()
Definition LockFreeList.h:328
FLockFreePointerListLIFORoot()
Definition LockFreeList.h:270
Definition LockFreeList.h:689
int32 Push(T *InPayload, uint32 Priority)
Definition LockFreeList.h:700
FStallingTaskQueue()
Definition LockFreeList.h:696
T * Pop(int32 MyThread, bool bAllowStall)
Definition LockFreeList.h:753
Definition ThreadSafeCounter.h:14
int32 Increment()
Definition ThreadSafeCounter.h:52
int32 Add(int32 Amount)
Definition ThreadSafeCounter.h:64
int32 GetValue() const
Definition ThreadSafeCounter.h:120
Definition LockFreeList.h:959
void PopAllAndClose(ContainerType &Output)
Definition LockFreeList.h:987
void Reset()
Definition LockFreeList.h:965
bool PushIfNotClosed(T *NewItem)
Definition LockFreeList.h:976
bool IsClosed() const
Definition LockFreeList.h:1002
Definition AssetRegistryState.h:50
Definition LockFreeList.h:60
T * GetItem(uint32 Index)
Definition LockFreeList.h:89
uint32 Alloc(uint32 Count=1)
Definition LockFreeList.h:76
TLockFreeAllocOnceIndexedAllocator()
Definition LockFreeList.h:67
Definition LockFreeList.h:910
UE_FORCEINLINE_HINT bool IsEmpty() const
Definition LockFreeList.h:950
T * Pop()
Definition LockFreeList.h:927
void PopAll(ContainerType &Output)
Definition LockFreeList.h:938
void Push(T *NewItem)
Definition LockFreeList.h:918
Definition LockFreeList.h:841
void PopAll(ContainerType &Output)
Definition LockFreeList.h:869
void Push(T *NewItem)
Definition LockFreeList.h:849
void PopAllAndApply(FunctorType InFunctor)
Definition LockFreeList.h:878
T * Pop()
Definition LockFreeList.h:858
UE_FORCEINLINE_HINT bool IsEmpty() const
Definition LockFreeList.h:890
Definition LockFreeList.h:898
Definition LockFreeList.h:904
Definition TestUtils.cpp:8
UE_STRING_CLASS Result(Forward< LhsType >(Lhs), RhsLen)
Definition String.cpp.inl:732
U16 Index
Definition radfft.cpp:71
Definition LockFreeList.h:224
std::atomic< uint32 > SingleNext
Definition LockFreeList.h:227
FIndexedPointer DoubleNext
Definition LockFreeList.h:225
std::atomic< void * > Payload
Definition LockFreeList.h:226
Definition LockFreeList.h:136
void Init()
Definition LockFreeList.h:141
UE_FORCEINLINE_HINT bool operator==(const FIndexedPointer &Other) const
Definition LockFreeList.h:209
UE_FORCEINLINE_HINT void SetPtr(uint32 To)
Definition LockFreeList.h:157
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:213
bool InterlockedCompareExchange(const FIndexedPointer &Exchange, const FIndexedPointer &Comparand)
Definition LockFreeList.h:202
void AdvanceCounterAndState(const FIndexedPointer &From, uint64 TABAInc)
Definition LockFreeList.h:172
UE_FORCEINLINE_HINT void SetCounterAndState(uint64 To)
Definition LockFreeList.h:167
void AtomicRead(const FIndexedPointer &Other)
Definition LockFreeList.h:195
void SetState(uint64 Value)
Definition LockFreeList.h:189
UE_FORCEINLINE_HINT uint64 GetCounterAndState() const
Definition LockFreeList.h:162
UE_FORCEINLINE_HINT uint32 GetPtr() const
Definition LockFreeList.h:152
UE_FORCEINLINE_HINT uint64 GetState() const
Definition LockFreeList.h:183
void SetAll(uint32 Ptr, uint64 CounterAndState)
Definition LockFreeList.h:146
Definition LockFreeList.h:232
static CORE_API uint32 AllocLockFreeLink()
Definition LockFreeList.cpp:264
@ MAX_BITS_IN_TLinkPtr
Definition LockFreeList.h:235
static CORE_API void FreeLockFreeLink(uint32 Item)
Definition LockFreeList.cpp:259
static CORE_API TAllocator LinkAllocator
Definition LockFreeList.h:257
TLockFreeAllocOnceIndexedAllocator< FIndexedLockFreeLink, MAX_LOCK_FREE_LINKS, 16384 > TAllocator
Definition LockFreeList.h:240
static UE_FORCEINLINE_HINT FIndexedLockFreeLink * IndexToLink(uint32 Index)
Definition LockFreeList.h:246
uint32 TLinkPtr
Definition LockFreeList.h:239
FIndexedPointer TDoublePtr
Definition LockFreeList.h:237
FIndexedLockFreeLink TLink
Definition LockFreeList.h:238
static UE_FORCEINLINE_HINT uint32 IndexToPtr(uint32 Index)
Definition LockFreeList.h:250
static UE_FORCEINLINE_HINT FIndexedLockFreeLink * DerefLink(uint32 Ptr)
Definition LockFreeList.h:242