ThreadWeaver 5.109.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
ThreadWeaver::DependencyPolicy

DependencyPolicy implements execution-time dependencies dependencies between Jobs. More...

#include <dependencypolicy.h>

Public Member Functions

 ~DependencyPolicy () override
 Destructor.
 
void addDependency (const Dependency &dep)
 
void addDependency (JobPointer jobA, JobPointer jobB)
 Add jobB as a dependency of jobA.
 
bool canRun (JobPointer) override
 canRun() is called before the job is executed.
 
void destructed (JobInterface *job) override
 destructing() is called when a Job that has this queue policy assigned gets destructed.
 
void free (JobPointer) override
 free() is called after the job has been executed.
 
bool isEmpty () const
 
void release (JobPointer) override
 release() is called if canRun() returned true, but the job has not been executed for external reasons.
 
bool removeDependency (const Dependency &dep)
 
bool removeDependency (JobPointer jobA, JobPointer jobB)
 Remove a dependency.
 
void resolveDependencies (JobPointer)
 Resolve all dependencies for a job.
 
virtual bool canRun (JobPointer)=0
 canRun() is called before the job is executed.
 
virtual void destructed (JobInterface *job)=0
 destructing() is called when a Job that has this queue policy assigned gets destructed.
 
virtual void free (JobPointer)=0
 free() is called after the job has been executed.
 
virtual void release (JobPointer)=0
 release() is called if canRun() returned true, but the job has not been executed for external reasons.
 

Static Public Member Functions

static DependencyPolicyinstance ()
 

Protected Member Functions

bool hasUnresolvedDependencies (JobPointer) const
 Query whether the job has an unresolved dependency.
 

Detailed Description

DependencyPolicy implements execution-time dependencies dependencies between Jobs.

To declare that Job B can only be executed when Job A is finished, call addDependency.

Be aware of circular dependencies. All dependencies on a Job will be removed if the Job object is destructed. Sequence uses dependencies to implement the ordered execution of the sequence elements.

Constructor & Destructor Documentation

◆ ~DependencyPolicy()

ThreadWeaver::DependencyPolicy::~DependencyPolicy ( )
override

Destructor.

Member Function Documentation

◆ addDependency()

void ThreadWeaver::DependencyPolicy::addDependency ( JobPointer  jobA,
JobPointer  jobB 
)

Add jobB as a dependency of jobA.

jobA will only be executed after jobB has been successfully processed.

Parameters
jobAthe depending job
jobBthe job jobA depends on

◆ canRun()

bool ThreadWeaver::DependencyPolicy::canRun ( JobPointer  )
overridevirtual

canRun() is called before the job is executed.

The job will only be executed if canRun() returns true.

Implements ThreadWeaver::QueuePolicy.

◆ destructed()

void ThreadWeaver::DependencyPolicy::destructed ( JobInterface *  job)
overridevirtual

destructing() is called when a Job that has this queue policy assigned gets destructed.

Implements ThreadWeaver::QueuePolicy.

◆ free()

void ThreadWeaver::DependencyPolicy::free ( JobPointer  )
overridevirtual

free() is called after the job has been executed.

It is guaranteed that free is called only after canRun() returned true at an earlier time.

Implements ThreadWeaver::QueuePolicy.

◆ hasUnresolvedDependencies()

bool ThreadWeaver::DependencyPolicy::hasUnresolvedDependencies ( JobPointer  ) const
protected

Query whether the job has an unresolved dependency.

In case it does, the policy will return false from canRun().

◆ release()

void ThreadWeaver::DependencyPolicy::release ( JobPointer  )
overridevirtual

release() is called if canRun() returned true, but the job has not been executed for external reasons.

For example, a second QueuePolicy could have returned false from canRun() for the same job.

Implements ThreadWeaver::QueuePolicy.

◆ removeDependency()

bool ThreadWeaver::DependencyPolicy::removeDependency ( JobPointer  jobA,
JobPointer  jobB 
)

Remove a dependency.

The dependency of jobA on jobB is removed. If no dependencies are left for jobA, canRun will return true. Returns false if the given object is not dependency of this job.

Parameters
jobAthe depending job
jobBthe job jobA depends on
Returns
true if dependency existed, false otherwise

◆ resolveDependencies()

void ThreadWeaver::DependencyPolicy::resolveDependencies ( JobPointer  )

Resolve all dependencies for a job.

This method is called after the Job has been finished, or when it is deleted without being executed (performed by the destructor). The method will remove all entries stating that another Job depends on this one.