JobGroupRef Class Reference

#include <jobgroup.h>

Inheritance diagram for JobGroupRef:

Detailed Description

Reference to a group (JobGroupInterface).

Public Member Functions

 MAXON_DEFAULT_REFERENCE_CONSTRUCTORS (JobGroupRef, Ptr)
 
const JobGroupRefEnqueue (JobQueueInterface *queue=JOBQUEUE_CURRENT) const
 
Result< void > EnqueueAndWait (JobQueueInterface *queue=JOBQUEUE_CURRENT) const
 
Bool Wait (TimeValue timeout=TIMEVALUE_INFINITE, WAITMODE mode=WAITMODE::DEFAULT) const
 
Result< void > GetResult (TimeValue timeout=TIMEVALUE_INFINITE, WAITMODE mode=WAITMODE::DEFAULT) const
 
template<typename... ARGS>
Result< void > Add (ARGS &&... args) const
 
template<JOBCANCELLATION B, typename T >
Result< void > Add (T &&obj, JOBGROUPADDFLAGS flags=JOBGROUPADDFLAGS::DEFAULT) const
 
ObservableFinishedBase< JobGroupInterfaceObservableFinished () const
 
void Cancel () const
 
void CancelAndWait (WAITMODE mode=WAITMODE::DEFAULT) const
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 
- Public Member Functions inherited from BaseRef< T, HANDLER >
T * GetPointer ()
 
ConstReferencedTypeGetPointer () const
 
T * operator-> ()
 
ConstReferencedTypeoperator-> () const
 
std::conditional< std::is_void< T >::value, DeleteReturnType01, T >::typeoperator* ()
 
std::conditional< std::is_void< ConstReferencedType >::value, DeleteReturnType01, T >::typeoperator* () const
 
 operator T* ()
 
 operator ConstReferencedType * () const
 
 operator Bool () const
 
 operator Bool ()
 
const std::conditional< std::is_void< T >::value, DeleteReturnType01, T >::typeoperator[] (Int) const =delete
 
ResultRef< typename std::remove_const< T >::typeMakeWritable (Bool resetOnError=true)
 
ResultRef< typename std::remove_const< T >::typeMakeWritableDontCopy ()
 
Bool HasMultipleReferences () const
 
std::conditional< std::is_void< T >::value, DeleteReturnType01, T >::typeGetOrDefault () const
 
 BaseRef ()
 
MAXON_IMPLICIT BaseRef (std::nullptr_t)=delete
 
MAXON_IMPLICIT BaseRef (T *o)
 
template<typename PTR >
 BaseRef (ForwardResultPtr< PTR > o)
 
 BaseRef (ResultPtr< T > o, Int)
 
 BaseRef (const BaseRef &src)
 
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
MAXON_IMPLICIT BaseRef (const REF &src)
 
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
MAXON_IMPLICIT BaseRef (REF &src)
 
BaseRefoperator= (T *src)
 
BaseRefoperator= (std::nullptr_t src)
 
BaseRefoperator= (const BaseRef &src)
 
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
BaseRefoperator= (const REF &src)
 
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
BaseRefoperator= (REF &src)
 
 BaseRef (BaseRef &&src)
 
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(const, REF) && !STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
MAXON_IMPLICIT BaseRef (REF &&src)
 
BaseRefoperator= (BaseRef &&src)
 
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(const, REF) && !STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
BaseRefoperator= (REF &&src)
 
 ~BaseRef ()
 
Bool operator== (const BaseRef &b) const
 
Bool operator!= (const BaseRef &b) const
 
Bool operator< (const BaseRef &b) const
 
 MAXON_OPERATOR_INEQUALITY (BaseRef)
 
Bool operator== (const T *b) const
 
Bool operator!= (const T *b) const
 
Bool operator== (typename std::remove_const< T >::type *b) const
 
Bool operator!= (typename std::remove_const< T >::type *b) const
 
Bool operator== (std::nullptr_t) const
 
Bool operator!= (std::nullptr_t) const
 
HashInt GetHashCode () const
 
UniqueHash GetUniqueHashCode () const
 
std::conditional< Bool(HANDLER::KIND &VALUEKIND::COW_MASK), typename std::remove_const< T >::type, T >::typeDisconnect ()
 
void PrivateSetTarget (ResultPtr< T > src)
 
void PrivateSetPointer (T *ptr)
 

Static Public Member Functions

static ResultMemT< JobGroupRefCreate (JOBGROUPFLAGS flags=JOBGROUPFLAGS::DEFAULT)
 
static MAXON_ATTRIBUTE_FORCE_INLINE const JobGroupRefDefaultValue ()
 
- Static Public Member Functions inherited from BaseRef< T, HANDLER >
static void PrivateLookupFn ()
 
static std::false_type GenericVarianceCheck (const void *)
 
template<typename... ARGS>
static MAXON_ATTRIBUTE_FORCE_INLINE ResultMemT< BaseRefCreate (ARGS &&... args)
 
static const BaseRefDefaultValueRef ()
 
static std::conditional< Bool(HANDLER::KIND &VALUEKIND::UNIQUE_REFERENCE), BaseRef, const BaseRef & >::type DefaultValue ()
 

Private Types

using Ptr = StrongRef< JobGroupInterface >
 

Additional Inherited Members

- Public Types inherited from BaseRef< T, HANDLER >
using ReferencedType = T
 
using ConstReferencedType = typename ConstIf< T, Bool(HANDLER::KIND &VALUEKIND::DEEP_CONSTNESS)>::type
 
using DirectlyReferencedType = T
 
using SelfType = BaseRef< T, HANDLER >
 
template<typename D >
using IsGenericBaseOf = std::true_type
 
using Handler = HANDLER
 
using RefCompareType = RefCompare< MAXON_IS_COW_KIND(HANDLER::KIND), IsInterfaceType< T >::value >
 
- Static Public Attributes inherited from BaseRef< T, HANDLER >
static constexpr Bool DIRECT_REF
 
- Protected Attributes inherited from BaseRef< T, HANDLER >
union {
   T *   _object
 
   const void *   _impl
 
}; 
 

Member Typedef Documentation

◆ Ptr

using Ptr = StrongRef<JobGroupInterface>
private

Member Function Documentation

◆ MAXON_DEFAULT_REFERENCE_CONSTRUCTORS()

MAXON_DEFAULT_REFERENCE_CONSTRUCTORS ( JobGroupRef  ,
Ptr   
)

◆ Create()

static ResultMemT<JobGroupRef> Create ( JOBGROUPFLAGS  flags = JOBGROUPFLAGS::DEFAULT)
static

Creates a JobGroup.

Parameters
[in]flagsCan be used to create an auto-enqueue group.
Returns
JobGroupRef on success, OutOfMemoryerror on failure.

◆ Enqueue()

const JobGroupRef& Enqueue ( JobQueueInterface queue = JOBQUEUE_CURRENT) const

Enqueues all jobs of the group including subgroups. This will add a reference and remove it when the object is no longer needed). Please note that a group (like a job) can only be enqueued once. THREADSAFE.

Parameters
[in]queueThe queue, use JOBQUEUE_CURRENT for the current queue.
Returns
Always reference to itself (for concatenation).

◆ EnqueueAndWait()

Result<void> EnqueueAndWait ( JobQueueInterface queue = JOBQUEUE_CURRENT) const

Enqueues all jobs of the group including subgroups and waits for them. This implicitely indicates to the system that the current job cannot continue until the group has finished. THREADSAFE.

Parameters
[in]queueThe queue, use JOBQUEUE_CURRENT for the current queue.
Returns
OK on success.

◆ Wait()

Bool Wait ( TimeValue  timeout = TIMEVALUE_INFINITE,
WAITMODE  mode = WAITMODE::DEFAULT 
) const

Waits until all jobs of the group have been executed.

Wait() might execute other jobs in the current queue until the group you are waiting for has finished or is timed out. Therefore you may 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 try to call Wait() from a job which did not enqueue the group it will immediately return false because this would lead to a deadlock.

Instead of waiting for some group 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.

Parameters
[in]timeoutMaximum wait interval (or TIMEVALUE_INFINITE for no time-out).
[in]modeWAITMODE::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.
Returns
True if successful, false if you try to wait inside an enqueued job.

◆ GetResult()

Result<void> GetResult ( TimeValue  timeout = TIMEVALUE_INFINITE,
WAITMODE  mode = WAITMODE::DEFAULT 
) const

Waits until the group has been executed and returns OK on success or any errors returned by its jobs. If there are errors this might return an AggregatedError. THREADSAFE.

Parameters
[in]timeoutMaximum wait interval (or TIMEVALUE_INFINITE for no time-out).
[in]modeWAITMODE::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.
Returns
OK on success.

◆ Add() [1/2]

Result<void> Add ( ARGS &&...  args) const

Adds a job, a lambda, a BaseArray of jobs or a whole subgroup. The group takes exclusive ownership of whatever is added.

If you add a job it will be deleted after it has been executed, when the group will be deleted or when adding the job fails. The job must have been created using the DefaultAllocator, e.g. with Create() or NewObj(). If you had created a job on the stack or used a custom allocator this would lead to a crash.

If you add a BaseArray with multiple jobs of the same type to the group (this is faster than single Add()s) the jobs and the memory for the array will be freed after they have been executed. If adding the jobs failed they and the memory will be deleted automatically. The array must use the DefaultAllocator for memory allocations. Do not use a custom allocator because this would lead to a crash.

If you add a subgroup this will add a reference to the group and remove it when the group is not accessed anymore. If adding a subgroup fails its reference will be removed and its jobs will be stopped.

As long as the group is not enqueued you can add jobs from any thread. As soon as it is enqueued only jobs belonging to the group are allowed to add further jobs. THREADSAFE.

Parameters
[in]argsA job, lambda, BaseArray of jobs or a subgroup.
Returns
OK on success.

◆ Add() [2/2]

Result<void> Add ( T &&  obj,
JOBGROUPADDFLAGS  flags = JOBGROUPADDFLAGS::DEFAULT 
) const

The same as above but with the ability to specify the behaviour on early cancellation.

◆ ObservableFinished()

ObservableFinishedBase<JobGroupInterface> ObservableFinished ( ) const

ObservableFinished is an observable that is triggered after this group has been executed. THREADSAFE.

Returns
Custom observable.

◆ Cancel()

void Cancel ( ) const

Asks the group to cancel execution of all jobs that are enqueued. Currently running jobs are not affected unless they call IsCancelled(). If this is a subgroup the parent group will be cancelled too. The call will not wait for the group to cancel and it can be called from any thread or job. THREADSAFE.

◆ CancelAndWait()

void CancelAndWait ( WAITMODE  mode = WAITMODE::DEFAULT) const

Asks the group to cancel execution and waits until it has finished. THREADSAFE.

Parameters
[in]modeWAITMODE::DEFAULT by default.

◆ DefaultValue()

static MAXON_ATTRIBUTE_FORCE_INLINE const JobGroupRef& DefaultValue ( )
static

Returns a default value of the JobGroupRef (see defaultvalue.h for more details).

Returns
A default value of the JobGroupRef.

◆ ToString()

String ToString ( const FormatStatement formatStatement = nullptr) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. Currently no additional formatting instructions are supported.
Returns
The converted result.