ThreadWeaver

collection.h
1 /* -*- C++ -*-
2  This file declares the Collection class.
3 
4  SPDX-FileCopyrightText: 2004-2013 Mirko Boehm <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef JOBCOLLECTION_H
10 #define JOBCOLLECTION_H
11 
12 #include "job.h"
13 #include "jobpointer.h"
14 
15 namespace ThreadWeaver
16 {
17 class Thread;
18 class CollectionExecuteWrapper;
19 
20 namespace Private
21 {
22 class Collection_Private;
23 }
24 
25 /** A Collection is a vector of Jobs that will be queued together.
26  * In a Collection, the order of execution of the elements is not specified.
27  *
28  * It is intended that the collection is set up first and then
29  * queued. After queuing, no further jobs should be added to the collection.
30  */
31 class THREADWEAVER_EXPORT Collection : public Job
32 {
33 public:
34  Collection();
35  Collection(ThreadWeaver::Private::Collection_Private *d);
36  ~Collection() override;
37 
38  /** Append a job to the collection.
39  *
40  * To use Collection, create the Job objects first, add them to the collection, and then queue it. After
41  * the collection has been queued, no further Jobs are supposed to be added.
42  *
43  * @note Once the job has been added, execute wrappers can no more be set on it */
44  virtual void addJob(JobPointer);
45 
46  /** Stop processing, dequeue all remaining Jobs.
47  * job is supposed to be an element of the collection.
48  */
49  // FIXME remove job argument?
51 
52  /** Return the number of elements in the collection. */
53  int elementCount() const;
54 
55 #if THREADWEAVER_ENABLE_DEPRECATED_SINCE(5, 0)
56  /** @deprecated Since 5.0, use elementCount(). */
57  THREADWEAVER_DEPRECATED_VERSION(5, 0, "Use Collection::elementCount()")
58  int jobListLength() const;
59 #endif
60 
61  /** @brief Add the job to this collection by pointer. */
62  Collection &operator<<(ThreadWeaver::JobInterface *job);
63 
64  /** @brief Add the job to this collection. */
66  Collection &operator<<(JobInterface &job);
67 
68 protected:
69  /** Overload to queue the collection. */
70  void aboutToBeQueued_locked(QueueAPI *api) override;
71 
72  /** Overload to dequeue the collection. */
73  void aboutToBeDequeued_locked(QueueAPI *api) override;
74 
75  /** Return a ref-erence to the job in the job list at position i. */
76  JobPointer jobAt(int i);
77 
78  // FIXME remove
79  /** Return the number of jobs in the joblist.
80  * Assumes that the mutex is being held.
81  */
82  virtual int jobListLength_locked() const;
83 
84 protected:
85  /** Overload the execute method. */
86  void execute(const JobPointer &job, Thread *) override;
87 
88  /** Overload run().
89  * We have to. */
90  void run(JobPointer self, Thread *thread) override;
91 
92 protected:
93  friend class CollectionExecuteWrapper; // needs to access d()
94  friend class Collection_Private;
95  ThreadWeaver::Private::Collection_Private *d();
96  const ThreadWeaver::Private::Collection_Private *d() const;
97 };
98 
99 }
100 
101 #endif
void stop(Ekos::AlignState mode)
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
A Job is a simple abstraction of an action that is to be executed in a thread context.
Definition: job.h:46
Thread represents a worker thread in a Queue's inventory.
Definition: thread.h:27
A Collection is a vector of Jobs that will be queued together.
Definition: collection.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 04:01:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.