17#ifndef USE_NAIVE_TLockFreeFixedSizeAllocator_TLSCacheBase
18#define USE_NAIVE_TLockFreeFixedSizeAllocator_TLSCacheBase (0)
21template<
int32 SIZE,
typename TBundleRecycler,
typename TTrackingCounter = FNoopCounter>
26 SIZE_PER_BUNDLE = 65536,
27 NUM_PER_BUNDLE = SIZE_PER_BUNDLE / SIZE
34 static_assert(SIZE >=
sizeof(
void*) && SIZE %
sizeof(
void*) == 0,
"Blocks in TLockFreeFixedSizeAllocator must be at least the size of a pointer.");
53#if USE_NAIVE_TLockFreeFixedSizeAllocator_TLSCacheBase
54 return FMemory::Malloc(SIZE);
56 FThreadLocalCache&
TLS = GetTLS();
58 if (!
TLS.PartialBundle)
62 TLS.PartialBundle =
TLS.FullBundle;
63 TLS.FullBundle =
nullptr;
67 TLS.PartialBundle = GlobalFreeListBundles.Pop();
68 if (!
TLS.PartialBundle)
70 TLS.PartialBundle = (
void**)FMemory::Malloc(SIZE_PER_BUNDLE);
71 void **
Next =
TLS.PartialBundle;
79 NumFree.Add(NUM_PER_BUNDLE);
82 TLS.NumPartial = NUM_PER_BUNDLE;
86 void* Result = (
void*)
TLS.PartialBundle;
87 TLS.PartialBundle = (
void**)*
TLS.PartialBundle;
89 check(
TLS.NumPartial >= 0 && ((!!
TLS.NumPartial) == (!!
TLS.PartialBundle)));
102#if USE_NAIVE_TLockFreeFixedSizeAllocator_TLSCacheBase
107 FThreadLocalCache&
TLS = GetTLS();
108 if (
TLS.NumPartial >= NUM_PER_BUNDLE)
112 GlobalFreeListBundles.Push(
TLS.FullBundle);
115 TLS.FullBundle =
TLS.PartialBundle;
116 TLS.PartialBundle =
nullptr;
119 *(
void**)Item = (
void*)
TLS.PartialBundle;
120 TLS.PartialBundle = (
void**)Item;
150 struct FThreadLocalCache
153 void **PartialBundle;
157 : FullBundle(nullptr)
158 , PartialBundle(nullptr)
164 FThreadLocalCache& GetTLS()
170 TLS =
new FThreadLocalCache();
194template<
int32 SIZE,
int TPaddingForCacheContention,
typename TTrackingCounter = FNoopCounter>
200 checkf(!AutoRTFM::IsClosed() || !AutoRTFM::IsOnCurrentTransactionStack(
this),
TEXT(
"Not allowed to construct a stack local within a transaction."));
206 AutoRTFM::PopAllOnAbortHandlers(
this);
230 if (Alignment <= 4096)
241 Memory = FMemory::Malloc(SIZE, Alignment);
284 while (
void* Mem = FreeList.
Pop())
300 return AutoRTFM::Open([&] {
return NumUsed.GetValue(); });
311 return AutoRTFM::Open([&] {
return NumFree.GetValue(); });
332template<
int32 SIZE,
int TPaddingForCacheContention,
typename TTrackingCounter = FNoopCounter>
342template<
class T,
int TPaddingForCacheContention>
386template<
class T,
int TPaddingForCacheContention>
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#define UE_NONCOPYABLE(TypeName)
Definition CoreMiscDefines.h:457
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ MIN_ALIGNMENT
Definition MemoryBase.h:27
Definition UnrealTemplate.h:321
Definition LockFreeFixedSizeAllocator.h:388
T * New()
Definition LockFreeFixedSizeAllocator.h:407
void * Allocate()
Definition LockFreeFixedSizeAllocator.h:396
void Free(T *Item)
Definition LockFreeFixedSizeAllocator.h:418
Definition LockFreeFixedSizeAllocator.h:344
void * Allocate()
Definition LockFreeFixedSizeAllocator.h:352
T * New()
Definition LockFreeFixedSizeAllocator.h:363
void Free(T *Item)
Definition LockFreeFixedSizeAllocator.h:374
Definition LockFreeFixedSizeAllocator.h:23
const TTrackingCounter & GetNumFree() const
Definition LockFreeFixedSizeAllocator.h:142
~TLockFreeFixedSizeAllocator_TLSCacheBase()
Definition LockFreeFixedSizeAllocator.h:39
void * Allocate()
Definition LockFreeFixedSizeAllocator.h:51
const TTrackingCounter & GetNumUsed() const
Definition LockFreeFixedSizeAllocator.h:131
void Free(void *Item)
Definition LockFreeFixedSizeAllocator.h:100
TLockFreeFixedSizeAllocator_TLSCacheBase()
Definition LockFreeFixedSizeAllocator.h:32
Definition LockFreeFixedSizeAllocator.h:334
Definition LockFreeFixedSizeAllocator.h:196
TLockFreeFixedSizeAllocator()
Definition LockFreeFixedSizeAllocator.h:198
TTrackingCounter::IntegerType GetNumUsed() const
Definition LockFreeFixedSizeAllocator.h:298
~TLockFreeFixedSizeAllocator()
Definition LockFreeFixedSizeAllocator.h:204
void Free(void *Item)
Definition LockFreeFixedSizeAllocator.h:261
void * Allocate(int32 Alignment=MIN_ALIGNMENT)
Definition LockFreeFixedSizeAllocator.h:220
void Trim()
Definition LockFreeFixedSizeAllocator.h:277
TTrackingCounter::IntegerType GetNumFree() const
Definition LockFreeFixedSizeAllocator.h:309
void Push(T *NewItem)
Definition LockFreeList.h:849
T * Pop()
Definition LockFreeList.h:858
Definition LockFreeList.h:904
U16 Index
Definition radfft.cpp:71
static uint32 AllocTlsSlot(void)
Definition AndroidPlatformTLS.h:30
static UE_FORCEINLINE_HINT void FreeTlsSlot(uint32 SlotIndex)
Definition AndroidPlatformTLS.h:67
static UE_FORCEINLINE_HINT void * GetTlsValue(uint32 SlotIndex)
Definition AndroidPlatformTLS.h:57
static UE_FORCEINLINE_HINT void SetTlsValue(uint32 SlotIndex, void *Value)
Definition AndroidPlatformTLS.h:47
static FORCENOINLINE CORE_API void Free(void *Original)
Definition UnrealMemory.cpp:685