1/* -*- C++ -*-
2 This file is part of ThreadWeaver.
3
4 SPDX-FileCopyrightText: 2004-2013 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef COLLECTION_COLLECTION_P_H
10#define COLLECTION_COLLECTION_P_H
11
12#include <QList>
13#include <QMutex>
14
15#include "executewrapper_p.h"
16#include "job_p.h"
17
18namespace ThreadWeaver
19{
20class Collection;
21
22namespace Private
23{
24class CollectionSelfExecuteWrapper : public ThreadWeaver::ExecuteWrapper
25{
26public:
27 void begin(const JobPointer &, Thread *) override;
28 void end(const JobPointer &, Thread *) override;
29
30 void callBegin();
31 void callEnd();
32
33private:
34 JobPointer job_;
35 Thread *thread_;
36};
37
38class Collection_Private : public Job_Private
39{
40public:
41 Collection_Private();
42 ~Collection_Private() override;
43
44 /** Dequeue all elements of the collection.
45 * Note: This will not dequeue the collection itself.
46 */
47 void dequeueElements(Collection *collection, bool queueApiIsLocked);
48
49 /** Perform the task usually done when one individual job is
50 * finished, but in our case only when the whole collection
51 * is finished or partly dequeued.
52 */
53 void finalCleanup(Collection *collection);
54
55 /** @brief Enqueue the elements of the collection. */
56 void enqueueElements();
57
58 void elementStarted(Collection *collection, JobPointer, Thread *);
59 void elementFinished(Collection *collection, JobPointer job, Thread *thread);
60
61 /** @brief Prepare to enqueue the elements. */
62 virtual void prepareToEnqueueElements();
63
64 virtual JobInterface::Status updateStatus(Collection *collection, JobPointer job);
65
66 /** @brief Process a completed element. */
67 virtual void processCompletedElement(Collection *collection, JobPointer job, Thread *thread);
68
69 /** @brief Implement stop. */
70 void stop(Collection *collection);
71
72 void requestAbort(Collection *collection);
73
74 /** @brief Called before an element will be dequeued. */
75 virtual void elementDequeued(const JobPointer &)
76 {
77 }
78
79 /* The elements of the collection. */
80 QList<JobPointer> elements;
81
82 /* The Weaver interface this collection is queued in. */
83 QueueAPI *api;
84
85 /* Counter for the finished jobs.
86 Set to the number of elements when started.
87 When zero, all elements are done.
88 */
89 QAtomicInt jobCounter;
90 QAtomicInt jobsStarted;
91 CollectionSelfExecuteWrapper selfExecuteWrapper;
92 JobPointer self;
93 bool selfIsExecuting;
94};
95
96}
97
98}
99
100#endif // COLLECTION_COLLECTION_P_H
101

source code of threadweaver/src/collection_p.h