ThreadWeaver

dependencypolicy.h
1 /* -*- C++ -*-
2  This file implements the DependencyPolicy class.
3 
4  SPDX-FileCopyrightText: 2004-2013 Mirko Boehm <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 
8  $Id: DebuggingAids.cpp 20 2005-08-08 21:02:51Z mirko $
9 */
10 
11 #ifndef DEPENDENCYPOLICY_H
12 #define DEPENDENCYPOLICY_H
13 
14 #include <QtGlobal>
15 
16 // template <typename T> class QList;
17 
18 #include "queuepolicy.h"
19 
20 namespace ThreadWeaver
21 {
22 class JobInterface;
23 class Dependency;
24 
25 /** @brief DependencyPolicy implements execution-time dependencies dependencies between Jobs.
26  *
27  * To declare that Job B can only be executed when Job A is finished, call addDependency.
28  *
29  * Be aware of circular dependencies. All dependencies on a Job will be removed if the Job object is destructed.
30  * Sequence uses dependencies to implement the ordered execution of the sequence elements.
31  */
32 class THREADWEAVER_EXPORT DependencyPolicy : public QueuePolicy
33 {
34 public:
35  /** Destructor. */
36  ~DependencyPolicy() override;
37 
38  /** @brief Add jobB as a dependency of jobA.
39  * jobA will only be executed after jobB has been successfully processed.
40  * @param jobA the depending job
41  * @param jobB the job jobA depends on
42  */
43  void addDependency(JobPointer jobA, JobPointer jobB);
44  void addDependency(const Dependency &dep);
45 
46  /** @brief Remove a dependency.
47  * The dependency of jobA on jobB is removed. If no dependencies are left for jobA, canRun will return true.
48  * Returns false if the given object is not dependency of this job.
49  * @param jobA the depending job
50  * @param jobB the job jobA depends on
51  * @return true if dependency existed, false otherwise
52  */
53  bool removeDependency(JobPointer jobA, JobPointer jobB);
54  bool removeDependency(const Dependency &dep);
55 
56  /** @brief Resolve all dependencies for a job.
57  * This method is called after the Job has been finished, or when it is deleted without being executed (performed by the
58  * destructor). The method will remove all entries stating that another Job depends on this one.
59  */
60  void resolveDependencies(JobPointer);
61 
62  // FIXME remove
63  // /** @brief Retrieve a list of dependencies of this job. */
64  // QList<JobPointer> getDependencies(JobPointer) const;
65 
66  static DependencyPolicy &instance();
67 
68  bool canRun(JobPointer) override;
69 
70  void free(JobPointer) override;
71 
72  void release(JobPointer) override;
73 
74  void destructed(JobInterface *job) override;
75 
76  bool isEmpty() const;
77 
78 protected:
79  /** @brief Query whether the job has an unresolved dependency.
80  * In case it does, the policy will return false from canRun().
81  */
82  bool hasUnresolvedDependencies(JobPointer) const;
83 
84 private:
86  class Private;
87  Private *const d;
88 };
89 
90 }
91 
92 #endif
virtual void release(quint64 objid)
DependencyPolicy implements execution-time dependencies dependencies between Jobs.
QueuePolicy is an interface for customizations of the queueing behaviour of jobs.
Definition: queuepolicy.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:09:38 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.