UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InterchangeTaskSystem.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Async/Future.h"
6#include "Containers/Array.h"
7#include "Containers/Map.h"
8#include "Containers/Ticker.h"
10#include "Misc/ScopeLock.h"
11
12#define INTERCHANGE_INVALID_TASK_ID 0xFFFFFFFFFFFFFFFF
13
15
16namespace UE::Interchange
17{
18 //Forward declare to add it has friend
19 class FInterchangeTaskSystem;
20
22 {
23 Waiting, //Task is queue for execution when prerequisite are terminate and resource are available
24 Executing, //Task is being executing
25 Done //Task was execute and is now terminate
26 };
27
29 {
30 GameThread, //Task will be tick in a ticker in the engine tick on the game thread. This is a safe place to manipulate UObject
31 AsyncThread //Task will be call on asynchronous thread, code running inside those task must be thread safe.
32 };
33
35 {
36 public:
39
41 {
43 {
44 if (Future.IsValid())
45 {
46 Future.Get();
47 }
48 }
49 }
50
52 {
53 return TaskId;
54 }
55
60
62 {
63 return PrerequisiteTasks;
64 }
65
67 {
68 FScopeLock TaskStatusLock(&TaskStatusCriticalSection);
69 return TaskStatus;
70 }
71
79 virtual void Execute() = 0;
80
96 INTERCHANGECORE_API void Wait() const;
97 protected:
98
99 //Only friend FInterchangeTaskSystem can set a new status
101
103
104 private:
105
106 mutable FCriticalSection TaskStatusCriticalSection;
109 TArray<uint64> PrerequisiteTasks;
110
111 //If a task is asynchronous the future will be set.
112 //The future will contain the task id when it will be ready.
113 TFuture<uint64> Future;
114
116 };
117
122 {
123 private:
125 TFunction<void()> ExecuteLambda;
126
127
128 public:
134
135 virtual EInterchangeTaskThread GetTaskThread() const override
136 {
137 return TaskThread;
138 }
139
140 virtual void Execute()
141 {
142 ExecuteLambda();
143 }
144 };
145
147 {
148 public:
154
155 //The interchange task system is a singleton
157
164
171
174
179 INTERCHANGECORE_API void CancelTask(const uint64 TaskId, const bool bCancelPrerequisites);
180
197
199 {
200 return OnTaskSystemTick;
201 }
202
203 private:
204
205 static bool bIsCreatingSingleton;
206
207 FOnInterchangeTaskSystemTick OnTaskSystemTick;
208
209 //Internal cancel request with no lock, lock is handle by the caller (CancelTask)
210 void InternalAddCancelRequestNoLock(const uint64 TaskId, bool bCancelPrerequisites);
211
215 void Tick();
216
217 //The ticker we use to tick in the engine tick
218 FTSTicker::FDelegateHandle TickTickerHandle;
219
220 // Store the tasks per id
222 mutable FCriticalSection TaskPerIdMapCriticalSection;
223
224 //When a task is done, we add it here and release the task. Prerequisite are search in the list and here.
225 //A clean up is done when the TaskPerIdMap is empty.
226 TSet<uint64> ReleaseAndDoneTasks;
227
228 //The priority value is a counter that is increment for each task added to the system to create the task id
229 //The lower task id are execute earlier if possible.
230 uint64 PriorityValue = 0;
231 FCriticalSection PriorityValueCriticalSection;
232
233 TArray<uint64> CancelTaskRequests;
234 FCriticalSection CancelTaskRequestsCriticalSection;
235 };
236} //namespace UE::Interchange
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define DECLARE_MULTICAST_DELEGATE(DelegateName)
Definition DelegateCombinations.h:23
#define INTERCHANGE_INVALID_TASK_ID
Definition InterchangeTaskSystem.h:12
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition ScopeLock.h:141
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
bool IsValid() const
Definition Future.h:267
ConstResultType Get() const
Definition Future.h:239
Definition Future.h:393
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition InterchangeTaskSystem.h:35
INTERCHANGECORE_API void Wait() const
Definition InterchangeTaskSystem.cpp:43
EInterchangeTaskStatus GetTaskStatus() const
Definition InterchangeTaskSystem.h:66
FInterchangeTaskBase()
Definition InterchangeTaskSystem.h:37
virtual ~FInterchangeTaskBase()
Definition InterchangeTaskSystem.h:40
const TArray< uint64 > & GetPrerequisiteTasks() const
Definition InterchangeTaskSystem.h:61
uint64 GetTaskId() const
Definition InterchangeTaskSystem.h:51
INTERCHANGECORE_API bool SetTaskStatus(EInterchangeTaskStatus NewTaskStatus)
Definition InterchangeTaskSystem.cpp:21
virtual EInterchangeTaskThread GetTaskThread() const
Definition InterchangeTaskSystem.h:56
INTERCHANGECORE_API void SetPrerequisites(const TArray< uint64 > &InPrerequisiteTasks)
Definition InterchangeTaskSystem.cpp:37
Definition InterchangeTaskSystem.h:122
virtual EInterchangeTaskThread GetTaskThread() const override
Definition InterchangeTaskSystem.h:135
FInterchangeTaskLambda(EInterchangeTaskThread InTaskThread, TFunction< void()> InExecuteLambda)
Definition InterchangeTaskSystem.h:129
virtual void Execute()
Definition InterchangeTaskSystem.h:140
Definition InterchangeTaskSystem.h:147
FOnInterchangeTaskSystemTick & OnTaskSystemTickDelegate()
Definition InterchangeTaskSystem.h:198
static INTERCHANGECORE_API FInterchangeTaskSystem & Get()
Definition InterchangeTaskSystem.cpp:56
INTERCHANGECORE_API void WaitUntilTasksComplete(const TArray< uint64 > &TasksToComplete)
Definition InterchangeTaskSystem.cpp:174
INTERCHANGECORE_API EInterchangeTaskStatus GetTaskStatus(const uint64 TaskId) const
Definition InterchangeTaskSystem.cpp:134
INTERCHANGECORE_API void CancelTask(const uint64 TaskId, const bool bCancelPrerequisites)
Definition InterchangeTaskSystem.cpp:167
FInterchangeTaskSystem()
Definition InterchangeTaskSystem.cpp:48
INTERCHANGECORE_API uint64 AddTask(TSharedPtr< FInterchangeTaskBase, ESPMode::ThreadSafe > Task, TArray< uint64 > &TaskPrerequisites)
Definition InterchangeTaskSystem.cpp:115
Definition InterchangeHelper.cpp:9
EInterchangeTaskThread
Definition InterchangeTaskSystem.h:29
EInterchangeTaskStatus
Definition InterchangeTaskSystem.h:22