Macros | |
#define | DISABLE_IF_LOOP_TYPE_IS_INT(TYPE, ...) |
Typedefs | |
using | Ptr = StrongRef< JobStatusInterface > |
using | ValueType = RESULTVALUETYPE |
using | ValueType = RESULTVALUETYPE |
using | ValueType = void |
using | ValueType = void |
template<typename RESULTVALUETYPE > | |
using | FutureRef = JobResultRef< RESULTVALUETYPE > |
using | ThreadRef = ThreadRefTemplate< ThreadInterface > |
Enumerations | |
enum class | JOBGROUPFLAGS { DEFAULT , ENQUEUEING_THREAD_WAITS , FINALIZE_ON_WAIT , THREAD_AFFINITY , NO_JOB_DESTRUCTOR } |
enum class | STATICJOBGROUPFLAGS { DEFAULT , WILL_RUN_FINALIZER , ENQUEUEING_THREAD_WAITS , THREAD_AFFINITY , NO_JOB_DESTRUCTOR } |
enum class | STATICJOBARRAYFLAGS { DEFAULT , INITIALIZE_LATER } |
enum class | JOBQUEUETYPE { MAINTHREAD , NONE , LOWESTPRIORITY , LOWPRIORITY , NORMALPRIORITY , SERVICEIO , THREADLESS } |
enum class | JOBQUEUEMODE { DEFAULT , SPIN_ON_IDLE , SLEEP_ON_IDLE , DETACH_THREADS , PSEUDO_THREADS } |
enum class | PARALLELFORFLAGS { INITTHREADED_FINALIZETHREADED , INITTHREADED_FINALIZESYNC , INITSYNC_FINALIZETHREADED , INITSYNC_FINALIZESYNC , NOINIT_NOFINALIZE } |
Variables | |
RESULTVALUETYPE | _result |
RESULTVALUETYPE | _result |
static const Int | JOBQUEUE_USEMAXIMUMTHREADS |
static const JobQueueInterface::Current | JOBQUEUE_CURRENT |
static const JobQueueInterface::None | JOBQUEUE_NONE |
static const Int | PARALLELFOR_DEFAULTGRANULARITY |
static const Int | PARALLELFOR_MINIMUMGRANULARITY |
static const Int | PARALLELFOR_USEMAXIMUMTHREADS |
static const Int | PARALLELFOR_DISABLETHREADING |
static const Int | PARALLELFOR_MAXIMUMDEPTH |
Bool | g_trackSpinlocks |
Friends | |
class | StrongRefHandler |
template<typename > | |
struct | ObservableFinishedBase |
template<typename > | |
struct | ObservableCancelledBase |
class | JobStatusInterface |
class | JobGroupInterface |
template<typename > | |
class | StaticJobGroupInterface |
class | TimerInterface |
class | StrongRefHandler |
template<typename > | |
struct | MoveToTuple |
template<typename , typename , typename , typename > | |
class | ContinuationJob |
template<typename > | |
struct | MoveToTuple |
template<typename , typename , typename , typename > | |
class | ContinuationJob |
template<typename > | |
struct | MoveToTuple |
template<typename , typename , typename , typename > | |
class | ContinuationJob |
template<typename > | |
struct | MoveToTuple |
template<typename , typename , typename , typename > | |
class | ContinuationJob |
template<typename FN > | |
auto | ExecuteOnMainThread (FN &&fn, WAITMODE waitMode, TimeValue wait) -> decltype(fn()) |
#define DISABLE_IF_LOOP_TYPE_IS_INT | ( | TYPE, | |
... | |||
) |
|
private |
|
protected |
|
protected |
|
protected |
|
protected |
using FutureRef = JobResultRef<RESULTVALUETYPE> |
using ThreadRef = ThreadRefTemplate<ThreadInterface> |
Reference to a thread (ThreadInterface).
|
strong |
Flags for enqueue options of a JobGroup.
Enumerator | |
---|---|
DEFAULT | Default case. |
ENQUEUEING_THREAD_WAITS | The enqueuing thread waits until the group has finished and might be used to execute jobs. |
FINALIZE_ON_WAIT | After Enqueue() further Add()s can be made which start the jobs ASAP. A following call to Wait() or GetResult() finalizes the group (no more jobs can be added). Can be useful if there is a lot of setup work before a job can be added. |
THREAD_AFFINITY | On Enqueue() each jobs is permanently assigned to a worker thread. This blocks load balancing and is therefore slower and only useful for special cases. If a group with thread affinity had more jobs than the queue had threads its jobs must not have dependencies or wait calls. Only supported for queues where thread affinity has been enabled. |
NO_JOB_DESTRUCTOR | The individual jobs do not require destruction. |
|
strong |
Flags describing the ownership of a StaticJobGroup. You don't have to bother using anything other than DEFAULT.
|
strong |
Initialization options for the StaticJobArray.
Enumerator | |
---|---|
DEFAULT | Default behaviour: Array is empty. |
INITIALIZE_LATER | Array consists of as many uninitialized elements as it has capacity. The caller will construct them later on (before it is added to the group). |
|
strong |
Type of job queue.
Enumerator | |
---|---|
MAINTHREAD | Jobs are executed on the main thread whenever the event loop can spare some time: there is only one queue of this type: use GetMainThreadQueue() to access it. |
NONE | Jobs are not enqueued but executed in the current context. |
LOWESTPRIORITY | Use lowest priority threads (worker threads have lowest priority and will not idle when waiting for new jobs or waiting for a group to finish). |
LOWPRIORITY | Use low priority threads. |
NORMALPRIORITY | Use normal priority threads (You should rarely have to create a queue with normal priority. Most of the time low priority is sufficient: This makes sure that you don't interfere with really important tasks and if available you still get all cpu power). |
SERVICEIO | Queue is used for IO and priority is adapted accordingly. Spinning on idle is not allowed. |
THREADLESS |
|
strong |
Options for the job queue.
|
strong |
Flags controlling the threading of the init and finalize section of ParallelFor. The default case is INITTHREADED_FINALIZESYNC. Each worker thread will independently call the init section for its part of the loop and then execute the loop body. The init section of a thread might be executed after any another thread has almost executed the whole loop - there's no guarantee that all init sections have finished before the loop body is entered, you might even have worker threads that don't run the init, loop and finalize section because another thread has already done the whole work. After the loop has finished for each init section the corresponding finalize will be called synchronously one after another. There might be cases where you must make sure that the init section for all worker threads has finished before the loop is executed, for example because you also must initialize some global variables for each worker thread that will be utilized by nested ParallelFors or other sub-jobs. Depending on your needs you might specify INITSYNC_FINALIZETHREADED,
Executes a lambda on the main thread and returns its result (if any). If the current thread is the main thread the lambda is executed directly. Otherwise a job will be enqueued and the function waits until it has finished. If the job does not return any values and can be executed asynchronously you might specify DONT_WAIT as waitMode parameter. The job is always guaranteed to be executed and this method will only return an error if the lambda does.
[in] | fn | Lambda object with the code to be executed. |
[in] | waitMode | DONT_WAIT if you don't want to wait, otherwise it defines the waitMode of the operation. Useful values are WAITMODE::RETURN_ON_CANCEL if you want to return on thrread cancelation to prevent dead locks |
[in] | timeout | The time to wait for the execution (infinite by default). |
JOBOPTIONFLAGS GetJobOptions | ( | ) | const |
const Char* GetName | ( | ) | const |
|
explicit |
Initializes the JobInterface including the jump table to the implementation methods.
[in] | jmpTable | Jump table of the implementation class. |
~JobInterface | ( | ) |
JobInterface | ( | JobInterface && | src | ) |
Move constructor is just for use with BaseArray (JobGroupInterface::Add())
JobInterface& operator= | ( | JobInterface && | src | ) |
Move assignment operator is just for use with BaseArray (JobGroupInterface::Add()).
Bool Wait | ( | TimeValue | timeout = TIMEVALUE_INFINITE , |
WAITMODE | mode = WAITMODE::DEFAULT |
||
) | const |
Waits until this job has been executed. As long as a job hasn't been started it is considered not to have finished yet. Once it has run this will return immediately.
Wait() might execute other jobs in the current queue until the one you are waiting for has finished or is timed out. Therefore you must never lock a shared resource another job might use as well and then wait. For one this could dead-lock and conceptually this would result in single-threaded performance.
If you call Wait() from within an enqueued job you must have enqueued what you are waiting for. Otherwise Wait() will immediately return false because this would lead to a deadlock. The same applies if a job tries to wait for itself.
Instead of waiting for a job to start some action after it has finished you can subscribe to ObservableFinished(). This cannot dead-lock, is more efficient and can even be used to run the observer in a different queue. For example you can run a job and register an observer for it that will run on the main thread's queue and updates the UI. THREADSAFE.
[in] | timeout | Maximum wait interval (or TIMEVALUE_INFINITE for no time-out). |
[in] | mode | WAITMODE::DEFAULT by default. WAITMODE::RETURN_ON_CANCEL means that Wait() will return if the caller has been cancelled even if the condition has not been set yet. |
Result<void> GetResult | ( | TimeValue | timeout = TIMEVALUE_INFINITE , |
WAITMODE | mode = WAITMODE::DEFAULT |
||
) | const |
Waits until this job has been executed and returns the result. THREADSAFE.
[in] | timeout | Maximum wait interval (or TIMEVALUE_INFINITE for no time-out). |
[in] | mode | WAITMODE::DEFAULT by default. WAITMODE::RETURN_ON_CANCEL means that Wait() will return if the caller has been cancelled even if the condition has not been set yet. |
Result<void> MoveResult | ( | TimeValue | timeout = TIMEVALUE_INFINITE , |
WAITMODE | mode = WAITMODE::DEFAULT |
||
) |
Waits until this job has been executed and returns the result via std::move.
[in] | timeout | Maximum wait interval (or TIMEVALUE_INFINITE for no time-out). |
[in] | mode | WAITMODE::DEFAULT by default. WAITMODE::RETURN_ON_CANCEL means that Wait() will return if the caller has been cancelled even if the condition has not been set yet. |
void Cancel | ( | ) |
Asks the job to cancel execution. If the job is a part of a group the whole group will be cancelled. Cancellation of a job does not affect its finish observers. The call will not wait for the job to cancel. THREADSAFE.
Bool IsCancelled | ( | ) | const |
Checks if the job should stop. THREADSAFE.
void CancelAndWait | ( | WAITMODE | mode = WAITMODE::DEFAULT | ) |
Asks the job to cancel execution and waits until it has finished. If the job is a part of a group the whole group will be cancelled. Cancellation of a job does not affect its finish observers. THREADSAFE.
[in] | mode | WAITMODE::DEFAULT by default. |
JobInterface* Enqueue | ( | JobQueueInterface * | queue = JOBQUEUE_CURRENT | ) |
Enqueues this job (will add a reference and remove it when the object is no longer needed). THREADSAFE.
[in] | queue | The queue, use JOBQUEUE_CURRENT for the current queue. |
Result<void> AddSubJob | ( | JobInterface * | subJob | ) |
Adds a job to this job's group (see JobGroup). The caller must belong to a group. THREADSAFE.
[in] | subJob | Job (nullptr will return error). |
Result<void> AddSubJob | ( | ResultMemT< JOB * > | subJob | ) |
Adds a job to this job's group (see JobGroup). The caller must belong to a group. THREADSAFE.
[in] | subJob | Job (nullptr will return error). |
Result<void> AddSubJob | ( | ResultMemT< JOBREF > && | subJob | ) |
Adds a job to this job's group (see JobGroup). The caller must belong to a group. THREADSAFE.
[in] | subJob | Job (encapsulated in a ResultMemT directly returned from creation). |
Result<void> AddSubGroup | ( | GROUP * | subGroup | ) |
Adds a subgroup to this job's group. The caller must belong to a group. THREADSAFE.
[in] | subGroup | Job group (nullptr will return error). |
Result<void> AddSubGroup | ( | ResultMemT< GROUP * > | subGroup | ) |
Adds a subgroup to this job's group. The caller must belong to a group. THREADSAFE.
[in] | subGroup | Job group (encapsulated in a ResultMemT directly returned from creation). |
Result<void> AddSubGroup | ( | ResultMemT< GROUP > | subGroup | ) |
Adds a subgroup to this job's group. The caller must belong to a group. THREADSAFE.
[in] | subGroup | Job group (encapsulated in a ResultMemT directly returned from creation). |
JobGroupInterface* GetJobGroup | ( | ) | const |
Returns the group a job belongs to. THREADSAFE.
ObservableFinishedBase<JobInterface> ObservableFinished | ( | ) |
ObservableFinished is an observable that is triggered after this job has been executed. THREADSAFE.
ObservableCancelledBase<JobInterface> ObservableCancelled | ( | ) |
ObservableCancelled is an observable that is triggered when this job is cancelled. THREADSAFE.
Result<void> Then | ( | JobInterface * | next, |
JobQueueInterface * | queue = JOBQUEUE_CURRENT |
||
) |
Adds an observer which is enqueued when this job has been executed. THREADSAFE.
|
static |
Returns the index of the internal worker thread which is running this job. If the job is not running as part of a worker thread 0 is returned to make sure you can safely use this as index to an array with thread local data. THREADSAFE.
|
static |
Returns the number of worker threads for the current job context. This might be different from the actual CPU core or thread count. THREADSAFE.
|
static |
Checks if the currently running job (or thread) should stop. Works for jobs and threads. THREADSAFE.
[in] | optionalJob | Optional job which should also be checked for cancellation. |
|
static |
Returns a pointer to the currently running job which can be used to check if it's cancelled. Works for jobs and threads.
String ToString | ( | const FormatStatement * | formatStatement = nullptr | ) | const |
Returns a readable string of the content.
[in] | formatStatement | Nullptr or additional formatting instruction. Currently no additional formatting instructions are supported. |
|
private |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Bool IsCancelled | ( | ) | const |
Checks if the job should stop. THREADSAFE.
JobGroupInterface* GetJobGroup | ( | ) | const |
Returns the group a job belongs to. THREADSAFE.
MAXON_DEFAULT_REFERENCE_CONSTRUCTORS | ( | JobStatusRef | , |
Ptr | |||
) |
MAXON_IMPLICIT JobStatusRef | ( | const Ptr & | src | ) |
MAXON_IMPLICIT JobStatusRef | ( | Ptr && | src | ) |
MAXON_IMPLICIT JobStatusRef | ( | const JobInterface * | src | ) |
MAXON_IMPLICIT JobStatusRef | ( | const ThreadInterface * | src | ) |
MAXON_IMPLICIT JobStatusRef | ( | const StrongRef< JobInterface > & | src | ) |
MAXON_IMPLICIT JobStatusRef | ( | const StrongRef< ThreadInterface > & | src | ) |
Bool IsCancelled | ( | ) | const |
Checks if the job should stop. A null reference will not be regarded as being cancelled. THREADSAFE.
JobGroupInterface* GetJobGroup | ( | ) | const |
Returns the group a job belongs to. THREADSAFE.
|
static |
Returns a null value of the JobRef (see nullvalue.h for more details).
String ToString | ( | const FormatStatement * | formatStatement = nullptr | ) | const |
Returns a readable string of the content.
[in] | formatStatement | Nullptr or additional formatting instruction. Currently no additional formatting instructions are supported. |
|
protected |
Result<RESULTVALUETYPE> GetResult | ( | TimeValue | timeout = TIMEVALUE_INFINITE , |
WAITMODE | mode = WAITMODE::DEFAULT |
||
) | const |
Waits until this job has been executed and returns the result. THREADSAFE.
[in] | timeout | Maximum wait interval (or TIMEVALUE_INFINITE for no time-out). |
[in] | mode | WAITMODE::DEFAULT by default. WAITMODE::RETURN_ON_CANCEL means that Wait() will return if the caller has been cancelled even if the condition has not been set yet. |
Result<RESULTVALUETYPE> MoveResult | ( | TimeValue | timeout = TIMEVALUE_INFINITE , |
WAITMODE | mode = WAITMODE::DEFAULT |
||
) |
Waits until this job has been executed and returns the result via std::move.
[in] | timeout | Maximum wait interval (or TIMEVALUE_INFINITE for no time-out). |
[in] | mode | WAITMODE::DEFAULT by default. WAITMODE::RETURN_ON_CANCEL means that Wait() will return if the caller has been cancelled even if the condition has not been set yet. |
|
protected |
Sets the result value returned by GetResult().
|
protected |
|
protected |
Result<RESULTVALUETYPE> GetResult | ( | TimeValue | timeout = TIMEVALUE_INFINITE , |
WAITMODE | mode = WAITMODE::DEFAULT |
||
) | const |
Waits until this job has been executed and returns the result. THREADSAFE.
[in] | timeout | Maximum wait interval (or TIMEVALUE_INFINITE for no time-out). |
[in] | mode | WAITMODE::DEFAULT by default. WAITMODE::RETURN_ON_CANCEL means that Wait() will return if the caller has been cancelled even if the condition has not been set yet. |
Result<RESULTVALUETYPE> MoveResult | ( | TimeValue | timeout = TIMEVALUE_INFINITE , |
WAITMODE | mode = WAITMODE::DEFAULT |
||
) |
Waits until this job has been executed and returns the result via std::move.
[in] | timeout | Maximum wait interval (or TIMEVALUE_INFINITE for no time-out). |
[in] | mode | WAITMODE::DEFAULT by default. WAITMODE::RETURN_ON_CANCEL means that Wait() will return if the caller has been cancelled even if the condition has not been set yet. |
|
protected |
Sets the result value returned by GetResult().
|
protected |
|
protected |
|
protected |
Sets the result value returned by GetResult() (in this specialisation the Result<void> is just forwarded).
|
protected |
|
protected |
|
protected |
Sets the result value returned by GetResult() (in this specialisiation just a dummy because it's void).
|
protected |
|
protected |
|
static |
Creates the job.
[in] | args | Arguments for the construcor. |
ARGS | Parameter types. |
|
private |
maxon::MAXON_DATATYPE | ( | JobRef | , |
"net.maxon.datatype.job" | |||
) |
enum maxon::JOBGROUPFLAGS maxon::MAXON_ENUM_FLAGS | ( | JOBGROUPFLAGS | ) |
enum maxon::STATICJOBGROUPFLAGS maxon::MAXON_ENUM_FLAGS | ( | STATICJOBGROUPFLAGS | ) |
enum maxon::STATICJOBARRAYFLAGS maxon::MAXON_ENUM_FLAGS | ( | STATICJOBARRAYFLAGS | ) |
enum maxon::JOBQUEUETYPE maxon::MAXON_ENUM_LIST | ( | JOBQUEUETYPE | ) |
enum maxon::JOBQUEUEMODE maxon::MAXON_ENUM_LIST | ( | JOBQUEUEMODE | ) |
enum maxon::PARALLELFORFLAGS maxon::MAXON_ENUM_FLAGS | ( | PARALLELFORFLAGS | ) |
Executes multiple functions in parallel and waits until they have finished. The parallel flag should be used for recursive code and set to false once the work item size is so small it wouldn't make sense to parallelize it any further. Please note that using ParallelInvoke() to parallelize a recursive algorithm is handy but will never perform as good as using a parallelized non-recursive algorithm because of the required synchronization at each recursion level. Execution of the parallel code is guaranteed - even under low memory conditions. If the lambdas do not return Result<void> the routine will return OK.
[in] | parallel | True for parallel execution, false if amount of work has become very small. |
[in] | args | Callable objects, usually lambdas. |
ARGS | Parameter types. |
maxon::MAXON_DATATYPE | ( | ThreadRef | , |
"net.maxon.datatype.threadref" | |||
) |
|
private |
|
private |
|
static |
|
static |
Equivalent to calling GetDestinationQueue(), you just save a function call.
|
static |
For notifications and timer jobs: Executes them immediately on the current thread.
|
static |
|
static |
|
static |
|
static |
|
static |
|
extern |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
Executes a lambda on the main thread and returns its result (if any). If the current thread is the main thread the lambda is executed directly. Otherwise a job will be enqueued and the function waits until it has finished. If the job does not return any values and can be executed asynchronously you might specify DONT_WAIT as waitMode parameter. The job is always guaranteed to be executed and this method will only return an error if the lambda does.
[in] | fn | Lambda object with the code to be executed. |
[in] | waitMode | DONT_WAIT if you don't want to wait, otherwise it defines the waitMode of the operation. Useful values are WAITMODE::RETURN_ON_CANCEL if you want to return on thrread cancelation to prevent dead locks |
[in] | timeout | The time to wait for the execution (infinite by default). |