Minor improvements

This commit is contained in:
Wojtek Figat
2024-04-22 18:10:58 +02:00
parent e795a8b037
commit 32b15f90ab
9 changed files with 36 additions and 91 deletions

View File

@@ -7,7 +7,6 @@
#include "Engine/Core/NonCopyable.h"
#include "Engine/Core/Enums.h"
#include "Engine/Core/Types/TimeSpan.h"
#include "Engine/Core/Collections/Array.h"
#include "Engine/Platform/Platform.h"
/// <summary>
@@ -188,8 +187,8 @@ public:
/// <param name="tasks">The tasks list to wait for.</param>
/// <param name="timeoutMilliseconds">The maximum amount of milliseconds to wait for the task to finish it's job. Timeout smaller/equal 0 will result in infinite waiting.</param>
/// <returns>True if any task failed or has been canceled or has timeout, otherwise false.</returns>
template<class T = Task>
static bool WaitAll(Array<T*>& tasks, double timeoutMilliseconds = -1)
template<class T = Task, typename AllocationType = HeapAllocation>
static bool WaitAll(Array<T*, AllocationType>& tasks, double timeoutMilliseconds = -1)
{
for (int32 i = 0; i < tasks.Count(); i++)
{
@@ -300,27 +299,22 @@ public:
/// <summary>
/// Cancels all the tasks from the list and clears it.
/// </summary>
template<class T = Task>
static void CancelAll(Array<T*>& tasks)
template<class T = Task, typename AllocationType = HeapAllocation>
static void CancelAll(Array<T*, AllocationType>& tasks)
{
for (int32 i = 0; i < tasks.Count(); i++)
{
tasks[i]->Cancel();
}
tasks.Clear();
}
protected:
/// <summary>
/// Executes this task.
/// It should be called by the task consumer (thread pool or other executor of this task type).
/// It calls run() and handles result).
/// Executes this task. It should be called by the task consumer (thread pool or other executor of this task type). It calls run() and handles result).
/// </summary>
void Execute();
/// <summary>
/// Runs the task specified operations
/// Does not handles any task related logic, only performs the actual job.
/// Runs the task specified operations. It does not handle any task related logic, but only performs the actual job.
/// </summary>
/// <returns>The task execution result. Returns true if failed, otherwise false.</returns>
virtual bool Run() = 0;