UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IoDispatcherBackend.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "IoDispatcher.h"
7#include "Misc/Optional.h"
10
11// TODO: Internal headers should not be included
14
15#define UE_IODISPATCHER_STATS_ENABLED (COUNTERSTRACE_ENABLED || CSV_PROFILER_STATS)
16
18
23{
24public:
28 void* BackendData = nullptr;
35
41
43 bool IsCancelled() const
44 {
45 return LastBackendError == EIoErrorCode::Cancelled;
46 }
47
49 bool IsFailed() const
50 {
51 return
52 LastBackendError != EIoErrorCode::Ok &&
53 LastBackendError != EIoErrorCode::Cancelled;
54 }
55
57 void SetFailed()
58 {
59 if (!IsCancelled())
60 {
61 LastBackendError = EIoErrorCode::ReadError;
62 }
63 }
64
66 {
67 if (!IsCancelled())
68 {
69 LastBackendError = InError;
70 }
71 }
72
74 bool HasBuffer() const
75 {
76 return Buffer.IsSet();
77 }
78
81
84 {
85 return Buffer.GetValue();
86 }
87
90 {
91 Buffer.Emplace(InBuffer);
92 }
93
95 {
96#if UE_IODISPATCHER_STATS_ENABLED
97 return StartTime;
98#else
99 return 0;
100#endif
101 }
102
103private:
104 friend class FIoDispatcherImpl;
105 friend class FIoRequest;
106 friend class FIoBatch;
107 friend class FIoRequestStats;
108
109 void AddRef()
110 {
111 RefCount.IncrementExchange();
112 }
113
114 void ReleaseRef()
115 {
116 if (RefCount.DecrementExchange() == 1)
117 {
118 FreeRequest();
119 }
120 }
121
122 void FreeRequest();
123
125 struct IIoDispatcherBackend* Backend = nullptr;
126 FIoBatchImpl* Batch = nullptr;
127#if UE_IODISPATCHER_STATS_ENABLED
128 uint64 StartTime = 0;
129#endif
131 FIoReadCallback Callback;
132 TAtomic<uint32> RefCount{ 0 };
134 EIoErrorCode LastBackendError = EIoErrorCode::Ok;
135};
136
137namespace UE::Private
138{
139
140struct FIoRequestListTraits
141{
142 using ElementType = FIoRequestImpl;
143
144 static FIoRequestImpl* GetNext(const FIoRequestImpl* Element)
145 {
146 return Element->NextRequest;
147 }
148
149 static void SetNext(FIoRequestImpl* Element, FIoRequestImpl* Next)
150 {
151 Element->NextRequest = Next;
152 }
153};
154
155} // namespace UE::Private
156
158
160
173
186{
192
194 virtual void Shutdown() {};
195
204
210
212 virtual void CancelIoRequest(FIoRequestImpl* Request) = 0;
213
215 virtual void UpdatePriorityForIoRequest(FIoRequestImpl* Request) = 0;
216
218 virtual bool DoesChunkExist(const FIoChunkId& ChunkId) const = 0;
219
221 virtual bool DoesChunkExist(const FIoChunkId& ChunkId, const FIoOffsetAndLength& ChunkRange) const { return DoesChunkExist(ChunkId); }
222
224 virtual TIoStatusOr<uint64> GetSizeForChunk(const FIoChunkId& ChunkId) const = 0;
225
227 virtual TIoStatusOr<uint64> GetSizeForChunk(const FIoChunkId& ChunkId, const FIoOffsetAndLength& ChunkRange, uint64& OutAvailable) const
228 {
229 TIoStatusOr<uint64> ChunkSize = GetSizeForChunk(ChunkId);
230 OutAvailable = ChunkSize.IsOk() ? ChunkSize.ValueOrDie() : 0;
231 return ChunkSize;
232 }
233
235 virtual TIoStatusOr<FIoMappedRegion> OpenMapped(const FIoChunkId& ChunkId, const FIoReadOptions& Options) = 0;
236
238 virtual const TCHAR* GetName() const = 0;
239};
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DELEGATE(DelegateName)
Definition DelegateCombinations.h:20
EIoErrorCode
Definition IoStatus.h:19
uint32 Size
Definition VulkanMemory.cpp:4034
Definition IoDispatcherPrivate.h:10
Definition IoDispatcher.h:285
Definition IoBuffer.h:15
Definition IoChunkId.h:64
Definition IoDispatcher.cpp:348
Definition IoDispatcher.h:165
Definition IoDispatcher.cpp:304
Definition IoDispatcherBackend.h:23
FIoChunkId ChunkId
Definition IoDispatcherBackend.h:30
FIoRequestImpl * NextRequest
Definition IoDispatcherBackend.h:26
bool IsCancelled() const
Definition IoDispatcherBackend.h:43
FIoRequestImpl(class FIoRequestAllocator &InAllocator)
Definition IoDispatcherBackend.h:36
void SetResult(FIoBuffer InBuffer)
Definition IoDispatcherBackend.h:89
FIoReadOptions Options
Definition IoDispatcherBackend.h:32
void * BackendData
Definition IoDispatcherBackend.h:28
bool HasBuffer() const
Definition IoDispatcherBackend.h:74
TSAN_ATOMIC(int32) Priority=0
void SetFailed()
Definition IoDispatcherBackend.h:57
void SetLastBackendError(EIoErrorCode InError)
Definition IoDispatcherBackend.h:65
uint64 GetStartTime() const
Definition IoDispatcherBackend.h:94
bool IsFailed() const
Definition IoDispatcherBackend.h:49
CORE_API void CreateBuffer(uint64 Size)
Definition IoDispatcher.cpp:1194
FIoBuffer & GetBuffer()
Definition IoDispatcherBackend.h:83
Definition IoDispatcher.cpp:191
Definition IoDispatcher.h:237
Definition Atomic.h:538
Definition IoStatus.h:101
const T & ValueOrDie()
Definition IoStatus.h:211
bool IsOk() const
Definition IoStatus.h:291
Definition SharedPointer.h:153
Definition InheritedContext.h:118
void CaptureInheritedContext()
Definition InheritedContext.h:121
@ Element
Definition Visu.h:18
uint32 GetNext(uint32 Index, const IndexType *NextIndexData, const uint32 NextIndexCount)
Definition CompactHashTable.h:116
Definition PackageReader.cpp:44
Definition IoContainerHeader.h:110
Definition IoDispatcherBackend.h:165
FIoSignatureErrorDelegate SignatureErrorDelegate
Definition IoDispatcherBackend.h:169
bool bIsMultiThreaded
Definition IoDispatcherBackend.h:171
FWakeUpIoDispatcherThreadDelegate WakeUpDispatcherThreadDelegate
Definition IoDispatcherBackend.h:167
Definition IoOffsetLength.h:12
Definition IoDispatcherBackend.h:186
virtual FIoRequestImpl * GetCompletedIoRequests()=0
virtual TIoStatusOr< uint64 > GetSizeForChunk(const FIoChunkId &ChunkId, const FIoOffsetAndLength &ChunkRange, uint64 &OutAvailable) const
Definition IoDispatcherBackend.h:227
virtual TIoStatusOr< FIoMappedRegion > OpenMapped(const FIoChunkId &ChunkId, const FIoReadOptions &Options)=0
virtual TIoStatusOr< uint64 > GetSizeForChunk(const FIoChunkId &ChunkId) const =0
virtual bool DoesChunkExist(const FIoChunkId &ChunkId) const =0
virtual bool DoesChunkExist(const FIoChunkId &ChunkId, const FIoOffsetAndLength &ChunkRange) const
Definition IoDispatcherBackend.h:221
virtual void Shutdown()
Definition IoDispatcherBackend.h:194
virtual void UpdatePriorityForIoRequest(FIoRequestImpl *Request)=0
virtual const TCHAR * GetName() const =0
virtual void Initialize(TSharedRef< const FIoDispatcherBackendContext > Context)=0
virtual void ResolveIoRequests(FIoRequestList Requests, FIoRequestList &OutUnresolved)=0
virtual void CancelIoRequest(FIoRequestImpl *Request)=0
Definition Optional.h:131
constexpr OptionalType & GetValue()
Definition Optional.h:443
constexpr bool IsSet() const
Definition Optional.h:69
OptionalType & Emplace(ArgsType &&... Args)
Definition Optional.h:323