ThreadWeaver

iddecorator.cpp
1 /* -*- C++ -*-
2  Base class for job decorators in ThreadWeaver.
3 
4  SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "collection.h"
10 #include "managedjobpointer.h"
11 #include "sequence.h"
12 
13 #include "iddecorator.h"
14 
15 namespace
16 {
17 const quintptr IdDecorator_AutoDelete = 1;
18 
19 }
20 
21 namespace ThreadWeaver
22 {
23 // Pssst: IdDecorator uses the d pointer to hold decoratee. It also uses d2 as a bitfield to store the
24 // autoDelete setting. The goal is not to require a dynamic allocation on creation.
25 IdDecorator::IdDecorator(JobInterface *decoratee, bool autoDelete)
26  : d1(reinterpret_cast<Private1 *>(decoratee))
27  , d2(nullptr)
28 {
29  setAutoDelete(autoDelete);
30 }
31 
32 IdDecorator::~IdDecorator()
33 {
34  // Do not assert here. IdDecorator can decorate a null pointer. Only assert if a method is called on a decorated
35  // null pointer.
36  if (autoDelete()) {
37  delete job();
38  }
39 }
40 
41 QMutex *IdDecorator::mutex() const
42 {
43  Q_ASSERT(d1);
44  return job()->mutex();
45 }
46 
47 void IdDecorator::run(JobPointer self, Thread *thread)
48 {
49  Q_ASSERT(d1);
50  job()->run(self, thread);
51 }
52 
53 void IdDecorator::defaultBegin(const JobPointer &self, Thread *thread)
54 {
55  Q_ASSERT(d1);
56  job()->defaultBegin(self, thread);
57 }
58 
59 void IdDecorator::defaultEnd(const JobPointer &self, Thread *thread)
60 {
61  Q_ASSERT(d1);
62  job()->defaultEnd(self, thread);
63 }
64 
65 void IdDecorator::removeQueuePolicy(QueuePolicy *policy)
66 {
67  Q_ASSERT(d1);
68  job()->removeQueuePolicy(policy);
69 }
70 
71 QList<QueuePolicy *> IdDecorator::queuePolicies() const
72 {
73  Q_ASSERT(d1);
74  return job()->queuePolicies();
75 }
76 
77 void IdDecorator::assignQueuePolicy(QueuePolicy *policy)
78 {
79  Q_ASSERT(d1);
80  job()->assignQueuePolicy(policy);
81 }
82 
83 bool IdDecorator::isFinished() const
84 {
85  Q_ASSERT(d1);
86  return job()->isFinished();
87 }
88 
89 void IdDecorator::aboutToBeQueued(QueueAPI *api)
90 {
91  Q_ASSERT(d1);
92  job()->aboutToBeQueued(api);
93 }
94 
95 void IdDecorator::aboutToBeQueued_locked(QueueAPI *api)
96 {
97  Q_ASSERT(d1);
98  job()->aboutToBeQueued_locked(api);
99 }
100 
101 void IdDecorator::aboutToBeDequeued(QueueAPI *api)
102 {
103  Q_ASSERT(d1);
104  job()->aboutToBeDequeued(api);
105 }
106 
107 void IdDecorator::aboutToBeDequeued_locked(QueueAPI *api)
108 {
109  Q_ASSERT(d1);
110  job()->aboutToBeDequeued_locked(api);
111 }
112 
113 void IdDecorator::requestAbort()
114 {
115  Q_ASSERT(d1);
116  job()->requestAbort();
117 }
118 
119 bool IdDecorator::success() const
120 {
121  Q_ASSERT(d1);
122  return job()->success();
123 }
124 
125 int IdDecorator::priority() const
126 {
127  Q_ASSERT(d1);
128  return job()->priority();
129 }
130 
131 void IdDecorator::setStatus(JobInterface::Status status)
132 {
133  Q_ASSERT(d1);
134  job()->setStatus(status);
135 }
136 
137 JobInterface::Status IdDecorator::status() const
138 {
139  Q_ASSERT(d1);
140  return job()->status();
141 }
142 
143 Executor *IdDecorator::executor() const
144 {
145  Q_ASSERT(d1);
146  return job()->executor();
147 }
148 
149 Executor *IdDecorator::setExecutor(Executor *executor)
150 {
151  Q_ASSERT(d1);
152  return job()->setExecutor(executor);
153 }
154 
155 void IdDecorator::execute(const JobPointer &self, ThreadWeaver::Thread *thread)
156 {
157  Q_ASSERT(d1);
158  job()->execute(self, thread);
159 }
160 
161 void IdDecorator::blockingExecute()
162 {
163  Q_ASSERT(d1);
164  job()->blockingExecute();
165 }
166 
167 const ThreadWeaver::JobInterface *IdDecorator::job() const
168 {
169  return reinterpret_cast<JobInterface *>(d1);
170 }
171 
172 JobInterface *IdDecorator::job()
173 {
174  return reinterpret_cast<JobInterface *>(d1);
175 }
176 
178 {
179  if (onOff) {
180  d2 = reinterpret_cast<IdDecorator::Private2 *>(IdDecorator_AutoDelete);
181  } else {
182  d2 = nullptr;
183  }
184 }
185 
187 {
188  return d2 == reinterpret_cast<IdDecorator::Private2 *>(IdDecorator_AutoDelete);
189 }
190 
192 {
193  return dynamic_cast<const Collection *>(job());
194 }
195 
197 {
198  return dynamic_cast<Collection *>(job());
199 }
200 
202 {
203  return dynamic_cast<const Sequence *>(job());
204 }
205 
207 {
208  return dynamic_cast<Sequence *>(job());
209 }
210 
211 }
const JobInterface * job() const
Retrieve the decorated job.
bool autoDelete() const
Will the decoratee be auto-deleted?
Q_SCRIPTABLE CaptureState status()
A Sequence is a vector of Jobs that will be executed in a sequence.
Definition: sequence.h:30
const Collection * collection() const
Retrieve the decorated job as a Collection.
Thread represents a worker thread in a Queue's inventory.
Definition: thread.h:27
void setAutoDelete(bool onOff)
Auto-delete the decoratee or not.
A Collection is a vector of Jobs that will be queued together.
Definition: collection.h:31
const Sequence * sequence() const
Retrieve the decorated job as a Sequence.
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.