// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Delegate.h" /// /// Lightweight multi-threaded jobs execution scheduler. Uses a pool of threads and supports work-stealing concept. /// API_CLASS(Static) class FLAXENGINE_API JobSystem { DECLARE_SCRIPTING_TYPE_MINIMAL(JobSystem); /// /// Dispatches the job for the execution. /// /// The job. Argument is an index of the job execution. /// The job executions count. /// The label identifying this dispatch. Can be used to wait for the execution end. API_FUNCTION() static int64 Dispatch(const Function& job, int32 jobCount = 1); /// /// Waits for all dispatched jobs to finish. /// API_FUNCTION() static void Wait(); /// /// Waits for all dispatched jobs until a given label to finish (i.e. waits for a Dispatch that returned that label). /// /// The label. API_FUNCTION() static void Wait(int64 label); /// /// Sets whether automatically start jobs execution on Dispatch. If disabled jobs won't be executed until it gets re-enabled. Can be used to optimize execution of multiple dispatches that should overlap. /// API_FUNCTION() static void SetJobStartingOnDispatch(bool value); };