ThreadWeaver::QueuePolicy Class

class ThreadWeaver::QueuePolicy

QueuePolicy is an interface for customizations of the queueing behaviour of jobs. More...

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

ThreadWeaver::DependencyPolicy and ThreadWeaver::ResourceRestrictionPolicy

Public Functions

virtual ~QueuePolicy()
virtual bool canRun(ThreadWeaver::JobPointer) = 0
virtual void destructed(ThreadWeaver::JobInterface *job) = 0
virtual void free(ThreadWeaver::JobPointer) = 0
virtual void release(ThreadWeaver::JobPointer) = 0

Detailed Description

A job can have a number of queue policies assigned. In that case, the job is only executed when the method canRun() of all assigned policies return true. For every call to canRun() that returns true, it is guaranteed that the method free() or the method release() is called. Calling free() means the job has been executed, while calling release() means the job was not executed for external reasons, and will be tried later on.

As an example, dependencies can be implemented using a QueuePolicy: canRun() returns true when the job has no unresolved dependencies. free() and release() are empty.

A job can have multiple queue policies assigned, and will only be executed if all of them return true from canRun() within the same execution attempt. Jobs only keep a reference to the QueuePolicy. Therefore, the same policy object can be assigned to multiple jobs and this way control the way all those jobs are executed. Jobs never assume ownership of their assigned queue policies.

Member Function Documentation

[virtual noexcept] QueuePolicy::~QueuePolicy()

[pure virtual] bool QueuePolicy::canRun(ThreadWeaver::JobPointer)

canRun() is called before the job is executed. The job will only be executed if canRun() returns true.

[pure virtual] void QueuePolicy::destructed(ThreadWeaver::JobInterface *job)

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

[pure virtual] void QueuePolicy::free(ThreadWeaver::JobPointer)

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.

[pure virtual] void QueuePolicy::release(ThreadWeaver::JobPointer)

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.