Add Task::WaitAll with a span of tasks and wrap around profiler macro
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "Engine/Core/Types/DateTime.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Core/Math/Math.h"
|
||||
#include "Engine/Core/Types/Span.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
|
||||
void Task::Start()
|
||||
@@ -72,6 +73,17 @@ bool Task::Wait(double timeoutMilliseconds) const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Task::WaitAll(const Span<Task*>& tasks, double timeoutMilliseconds)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
for (int32 i = 0; i < tasks.Length(); i++)
|
||||
{
|
||||
if (tasks[i]->Wait())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Task* Task::ContinueWith(Task* task)
|
||||
{
|
||||
ASSERT(task != nullptr && task != this);
|
||||
|
||||
@@ -181,6 +181,14 @@ public:
|
||||
/// <returns>True if task failed or has been canceled or has timeout, otherwise false.</returns>
|
||||
bool Wait(double timeoutMilliseconds = -1) const;
|
||||
|
||||
/// <summary>
|
||||
/// Waits for all the tasks from the list.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
static bool WaitAll(const Span<Task*>& tasks, double timeoutMilliseconds = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Waits for all the tasks from the list.
|
||||
/// </summary>
|
||||
@@ -188,14 +196,9 @@ public:
|
||||
/// <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, typename AllocationType = HeapAllocation>
|
||||
static bool WaitAll(Array<T*, AllocationType>& tasks, double timeoutMilliseconds = -1)
|
||||
static bool WaitAll(const Array<T*, AllocationType>& tasks, double timeoutMilliseconds = -1)
|
||||
{
|
||||
for (int32 i = 0; i < tasks.Count(); i++)
|
||||
{
|
||||
if (tasks[i]->Wait())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return WaitAll(ToSpan(tasks), timeoutMilliseconds);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user