5#include "Containers/Map.h"
11#include "Misc/Optional.h"
38 check(ManagerThreadId == 0);
80template <
typename ElementType,
typename Traits = FManagedStorageDefaultTraits>
87 template <
typename ExternalHandleType>
112 return ExternalHandle.IsValid();
118 ExternalHandle.Invalidate();
123 return ExternalHandle ==
Other.ExternalHandle;
128 return ExternalHandle !=
Other.ExternalHandle;
138 return IsValid() ? FString::Printf(
TEXT(
"Internal:[ext:%s, idx:%d]"), *ExternalHandle.ToString(), InternalIndex) : FString(
TEXT(
"<invalid>"));
144 return ExternalHandle;
150 return InternalIndex;
169 struct FRemoveRequest
184 FStorageType Storage;
200 , StorageHandleIndex()
216 return Traits::IsManagerThread(ManagerThreadId);
226 Traits::CheckNotInitialized(ManagerThreadId);
227 ManagerThreadId = Traits::GetCurrentThreadId();
245 Traits::CheckIsManagerThread(ManagerThreadId);
252 FAddRequest AddRequest;
253 while (AddRequests.
Dequeue(AddRequest))
261 FAddRequest AddRequest;
262 while (AddRequests.
Dequeue(AddRequest))
264 AddImpl(AddRequest.Handle,
MoveTemp(AddRequest.Data));
272 FRemoveRequest RemoveRequest;
273 while (RemoveRequests.
Dequeue(RemoveRequest))
275 OutRemovedHandles->Add(RemoveImpl(RemoveRequest.Handle, RemoveRequest.OnComplete));
281 FRemoveRequest RemoveRequest;
282 while (RemoveRequests.
Dequeue(RemoveRequest))
284 RemoveImpl(RemoveRequest.Handle, RemoveRequest.OnComplete);
330 RemoveImpl(
Handle.GetExternalHandle(),
nullptr);
342 CheckThreadForStorageAccess();
343 return Storage.Num();
348 CheckThreadForStorageAccess();
349 return Storage.IsEmpty();
354 CheckThreadForStorageAccess();
373 CheckThreadForStorageAccess();
382 return Entry.InternalHandle ==
Handle ? &Entry.Data :
nullptr;
399 template <
bool bConst>
403 using TInternalIterator =
typename FStorageType::TRangedForIterator;
404 using StorageIteratorType = std::conditional_t<bConst, typename FStorageType::TRangedForConstIterator, typename FStorageType::TRangedForIterator>;
405 using InternalElementType = std::conditional_t<bConst, const ElementType, ElementType>;
414 ElementAccess.Emplace(
ItElementType{StorageIterator->InternalHandle, StorageIterator->Data});
423 ElementAccess.Emplace(
ItElementType{StorageIterator->InternalHandle, StorageIterator->Data});
432 inline explicit operator bool()
const
434 return !!StorageIterator;
447 StorageIteratorType StorageIterator;
456 CheckThreadForStorageAccess();
462 CheckThreadForStorageAccess();
468 CheckThreadForStorageAccess();
474 CheckThreadForStorageAccess();
479 inline void CheckThreadForStorageAccess()
const
481 if constexpr (Traits::bStorageAccessThreadChecksEnabled)
483 Traits::CheckIsManagerThread(ManagerThreadId);
491 new(Allocation) FStorageEntry{ InternalHandle,
MoveTemp(Data)};
493 return InternalHandle;
500 if (StorageHandleIndex.RemoveAndCopyValue(
Handle, FoundIndex) && Storage.IsValidIndex(FoundIndex))
502 InternalHandle = Storage[FoundIndex].InternalHandle;
503 Storage.RemoveAt(FoundIndex);
511 return InternalHandle;
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define QUICK_SCOPE_CYCLE_COUNTER(Stat)
Definition Stats.h:652
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
OnComplete(MoveTemp(Response))
const bool
Definition NetworkReplayStreaming.h:178
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
int32 InternalIndex
Definition VulkanMemory.cpp:4036
Definition UnrealTemplate.h:321
Definition UnrealString.h.inl:34
Definition MpscQueue.h:18
TOptional< ElementType > Dequeue()
Definition MpscQueue.h:58
void Enqueue(ArgTypes &&... Args)
Definition MpscQueue.h:49
Definition ContainerAllocationPolicies.h:894
Definition SparseArray.h:524
Definition EventLoopManagedStorage.h:401
ItElementType * operator->() const
Definition EventLoopManagedStorage.h:444
bool operator!() const
Definition EventLoopManagedStorage.h:438
TBaseRangeForIterator(StorageIteratorType InStorageIterator)
Definition EventLoopManagedStorage.h:409
bool operator==(const TBaseRangeForIterator &Rhs) const
Definition EventLoopManagedStorage.h:428
TBaseRangeForIterator & operator++()
Definition EventLoopManagedStorage.h:418
ItElementType & operator*() const
Definition EventLoopManagedStorage.h:443
bool operator!=(const TBaseRangeForIterator &Rhs) const
Definition EventLoopManagedStorage.h:429
Definition EventLoopManagedStorage.h:82
TBaseRangeForIterator< false > TRangedForIterator
Definition EventLoopManagedStorage.h:451
void Remove(const FInternalHandle Handle)
Definition EventLoopManagedStorage.h:328
TManagedStorageInternalHandle< FExternalHandle > FInternalHandle
Definition EventLoopManagedStorage.h:159
TBaseRangeForIterator< true > TRangedForConstIterator
Definition EventLoopManagedStorage.h:452
ElementType * Find(FInternalHandle Handle)
Definition EventLoopManagedStorage.h:371
TManagedStorage()
Definition EventLoopManagedStorage.h:198
TRangedForIterator end()
Definition EventLoopManagedStorage.h:466
ElementType * Find(FExternalHandle Handle)
Definition EventLoopManagedStorage.h:352
typename Traits::FExternalHandle FExternalHandle
Definition EventLoopManagedStorage.h:158
TRangedForConstIterator begin() const
Definition EventLoopManagedStorage.h:460
TRangedForConstIterator end() const
Definition EventLoopManagedStorage.h:472
bool IsManagerThread() const
Definition EventLoopManagedStorage.h:214
~TManagedStorage()
Definition EventLoopManagedStorage.h:207
const ElementType * Find(FInternalHandle Handle) const
Definition EventLoopManagedStorage.h:388
bool IsEmpty() const
Definition EventLoopManagedStorage.h:346
uint32 Update(FInternalHandleArryType *OutAddedHandles=nullptr, FInternalHandleArryType *OutRemovedHandles=nullptr)
Definition EventLoopManagedStorage.h:241
void Init()
Definition EventLoopManagedStorage.h:224
TRangedForIterator begin()
Definition EventLoopManagedStorage.h:454
void Remove(const FExternalHandle Handle, FManagedStorageOnRemoveComplete &&OnRemoveComplete=FManagedStorageOnRemoveComplete())
Definition EventLoopManagedStorage.h:316
const ElementType * Find(FExternalHandle Handle) const
Definition EventLoopManagedStorage.h:366
FExternalHandle Add(ElementType &&Data)
Definition EventLoopManagedStorage.h:300
int32 Num() const
Definition EventLoopManagedStorage.h:340
Definition EventLoopLog.cpp:5
TUniqueFunction< void()> FManagedStorageOnRemoveComplete
Definition EventLoopManagedStorage.h:17
static uint32 GetCurrentThreadId(void)
Definition AndroidPlatformTLS.h:20
Definition SparseArray.h:31
int32 Index
Definition SparseArray.h:32
Definition Optional.h:131
Definition EventLoopManagedStorage.h:20
static constexpr TCHAR Name[]
Definition EventLoopManagedStorage.h:21
Definition EventLoopManagedStorage.h:54
static constexpr bool bStorageAccessThreadChecksEnabled
Definition EventLoopManagedStorage.h:68
Definition EventLoopManagedStorage.h:25
static uint32 GetCurrentThreadId()
Definition EventLoopManagedStorage.h:26
static bool IsManagerThread(uint32 ManagerThreadId)
Definition EventLoopManagedStorage.h:31
static void CheckIsManagerThread(uint32 ManagerThreadId)
Definition EventLoopManagedStorage.h:41
static void CheckNotInitialized(uint32 ManagerThreadId)
Definition EventLoopManagedStorage.h:36
Definition EventLoopManagedStorage.h:89
TManagedStorageInternalHandle(EGenerateNewHandleType, ExternalHandleType InExternalHandle, int32 InInternalIndex)
Definition EventLoopManagedStorage.h:103
int32 GetInternalIndex() const
Definition EventLoopManagedStorage.h:148
bool IsValid() const
Definition EventLoopManagedStorage.h:110
bool operator!=(const TManagedStorageInternalHandle &Other) const
Definition EventLoopManagedStorage.h:126
FString ToString() const
Definition EventLoopManagedStorage.h:136
EGenerateNewHandleType
Definition EventLoopManagedStorage.h:91
@ GenerateNewHandle
Definition EventLoopManagedStorage.h:92
ExternalHandleType GetExternalHandle() const
Definition EventLoopManagedStorage.h:142
bool operator==(const TManagedStorageInternalHandle &Other) const
Definition EventLoopManagedStorage.h:121
void Invalidate()
Definition EventLoopManagedStorage.h:116
friend uint32 GetTypeHash(const TManagedStorageInternalHandle &InHandle)
Definition EventLoopManagedStorage.h:131
TManagedStorageInternalHandle()
Definition EventLoopManagedStorage.h:96
Definition EventLoopHandle.h:12