Add JobSystem.Execute utility for quick jobs running
This commit is contained in:
@@ -212,6 +212,23 @@ int32 JobSystemThread::Run()
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void JobSystem::Execute(const Function<void(int32)>& job, int32 jobCount)
|
||||||
|
{
|
||||||
|
// TODO: disable async if called on job thread? or maybe Wait should handle waiting in job thread to do the processing?
|
||||||
|
if (jobCount > 1)
|
||||||
|
{
|
||||||
|
// Async
|
||||||
|
const int64 jobWaitHandle = Dispatch(job, jobCount);
|
||||||
|
Wait(jobWaitHandle);
|
||||||
|
}
|
||||||
|
else if (jobCount > 0)
|
||||||
|
{
|
||||||
|
// Sync
|
||||||
|
for (int32 i = 0; i < jobCount; i++)
|
||||||
|
job(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int64 JobSystem::Dispatch(const Function<void(int32)>& job, int32 jobCount)
|
int64 JobSystem::Dispatch(const Function<void(int32)>& job, int32 jobCount)
|
||||||
{
|
{
|
||||||
PROFILE_CPU();
|
PROFILE_CPU();
|
||||||
|
|||||||
@@ -9,7 +9,14 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
API_CLASS(Static) class FLAXENGINE_API JobSystem
|
API_CLASS(Static) class FLAXENGINE_API JobSystem
|
||||||
{
|
{
|
||||||
DECLARE_SCRIPTING_TYPE_MINIMAL(JobSystem);
|
DECLARE_SCRIPTING_TYPE_MINIMAL(JobSystem);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes the job (utility to call dispatch and wait for the end).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="job">The job. Argument is an index of the job execution.</param>
|
||||||
|
/// <param name="jobCount">The job executions count.</param>
|
||||||
|
API_FUNCTION() static void Execute(const Function<void(int32)>& job, int32 jobCount = 1);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispatches the job for the execution.
|
/// Dispatches the job for the execution.
|
||||||
|
|||||||
Reference in New Issue
Block a user