ThreadWeaver::DependencyPolicy Class

class ThreadWeaver::DependencyPolicy

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

Header: #include <ThreadWeaver/DependencyPolicy>
CMake: find_package(KF6 REQUIRED COMPONENTS ThreadWeaver)
target_link_libraries(mytarget PRIVATE KF6::ThreadWeaver)
Inherits: ThreadWeaver::QueuePolicy

Public Functions

virtual ~DependencyPolicy() override
void addDependency(ThreadWeaver::JobPointer jobA, ThreadWeaver::JobPointer jobB)
bool isEmpty() const
bool removeDependency(ThreadWeaver::JobPointer jobA, ThreadWeaver::JobPointer jobB)
void resolveDependencies(ThreadWeaver::JobPointer)

Static Public Members

ThreadWeaver::DependencyPolicy &instance()

Protected Functions

bool hasUnresolvedDependencies(ThreadWeaver::JobPointer) const

Detailed Description

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.

Member Function Documentation

[override virtual noexcept] DependencyPolicy::~DependencyPolicy()

Destructor.

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

Add jobB as a dependency of jobA.

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

jobA the depending job

jobB the job jobA depends on

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

Query whether the job has an unresolved dependency.

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

[static] ThreadWeaver::DependencyPolicy &DependencyPolicy::instance()

bool DependencyPolicy::isEmpty() const

bool DependencyPolicy::removeDependency(ThreadWeaver::JobPointer jobA, ThreadWeaver::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.

jobA the depending job

jobB the job jobA depends on

Returns true if dependency existed, false otherwise

void DependencyPolicy::resolveDependencies(ThreadWeaver::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.