1/* -*- C++ -*-
2 This file implements the DependencyPolicy class.
3
4 SPDX-FileCopyrightText: 2004-2013 Mirko Boehm <mirko@kde.org>
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
20namespace ThreadWeaver
21{
22class JobInterface;
23class Dependency;
24
25/*!
26 * \class ThreadWeaver::DependencyPolicy
27 * \inheaderfile ThreadWeaver/DependencyPolicy
28 * \inmodule ThreadWeaver
29 *
30 * \brief DependencyPolicy implements execution-time dependencies dependencies between Jobs.
31 *
32 * To declare that Job B can only be executed when Job A is finished, call addDependency.
33 *
34 * Be aware of circular dependencies. All dependencies on a Job will be removed if the Job object is destructed.
35 * Sequence uses dependencies to implement the ordered execution of the sequence elements.
36 */
37class THREADWEAVER_EXPORT DependencyPolicy : public QueuePolicy
38{
39public:
40 /*! Destructor. */
41 ~DependencyPolicy() override;
42
43 /*!
44 * \brief Add jobB as a dependency of jobA.
45 *
46 * jobA will only be executed after jobB has been successfully processed.
47 *
48 * \a jobA the depending job
49 *
50 * \a jobB the job jobA depends on
51 */
52 void addDependency(JobPointer jobA, JobPointer jobB);
53 void addDependency(const Dependency &dep);
54
55 /*!
56 * \brief Remove a dependency.
57 *
58 * The dependency of jobA on jobB is removed. If no dependencies are left for jobA, canRun will return true.
59 *
60 * Returns false if the given object is not dependency of this job.
61 *
62 * \a jobA the depending job
63 *
64 * \a jobB the job jobA depends on
65 *
66 * Returns true if dependency existed, false otherwise
67 */
68 bool removeDependency(JobPointer jobA, JobPointer jobB);
69 bool removeDependency(const Dependency &dep);
70
71 /*!
72 * \brief Resolve all dependencies for a job.
73 *
74 * This method is called after the Job has been finished, or when it is deleted without being executed (performed by the
75 * destructor). The method will remove all entries stating that another Job depends on this one.
76 */
77 void resolveDependencies(JobPointer);
78
79 // FIXME remove
80 // /*! \brief Retrieve a list of dependencies of this job. */
81 // QList<JobPointer> getDependencies(JobPointer) const;
82
83 /*!
84 */
85 static DependencyPolicy &instance();
86
87 bool canRun(JobPointer) override;
88
89 void free(JobPointer) override;
90
91 void release(JobPointer) override;
92
93 void destructed(JobInterface *job) override;
94
95 /*!
96 */
97 bool isEmpty() const;
98
99protected:
100 /*!
101 * \brief Query whether the job has an unresolved dependency.
102 *
103 * In case it does, the policy will return false from canRun().
104 */
105 bool hasUnresolvedDependencies(JobPointer) const;
106
107private:
108 /*!
109 */
110 DependencyPolicy();
111 class Private;
112 Private *const d;
113};
114
115}
116
117#endif
118

source code of threadweaver/src/dependencypolicy.h