ThreadWeaver

queue.h
1 /* -*- C++ -*-
2  The Queue class 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 #ifndef THREADWEAVER_QUEUE_H
10 #define THREADWEAVER_QUEUE_H
11 
12 #include <QObject>
13 
14 #include "queuesignals.h"
15 #include "queuestream.h"
16 
17 namespace ThreadWeaver
18 {
19 class Job;
20 class State;
21 
22 /** @brief Queue implements a ThreadWeaver job queue.
23  *
24  * Queues process jobs enqueued in them by automatically assigning them to worker threads they manage.
25  * Applications using ThreadWeaver can make use of a global Queue which is instantiated on demand, or
26  * create multiple queues as needed. A job assigned to a queue will be processed by that specific queue.
27  *
28  * Worker threads are created by the queues as needed. To create a customized global queue,
29  * see GlobalQueueFactory.
30  *
31  * @see GlobalQueueFactory
32  * @see Queue::enqueue()
33  * @see Queue::instance()
34  */
35 class THREADWEAVER_EXPORT Queue : public QueueSignals
36 {
37  Q_OBJECT
38 public:
39  explicit Queue(QObject *parent = nullptr);
40  /** @brief Construct a queue with a customized implementation
41  * The queue takes ownership and will delete the implementation upon destruction. */
42  explicit Queue(QueueSignals *implementation, QObject *parent = nullptr);
43  ~Queue() override;
44 
45  QueueStream stream();
46 
47  const State *state() const override;
48 
49  void setMaximumNumberOfThreads(int cap) override;
50  int maximumNumberOfThreads() const override;
51  int currentNumberOfThreads() const override;
52 
53  static ThreadWeaver::Queue *instance();
54  void enqueue(const QVector<JobPointer> &jobs) override;
55  void enqueue(const JobPointer &job);
56  bool dequeue(const JobPointer &) override;
57  void dequeue() override;
58  void finish() override;
59  void suspend() override;
60  void resume() override;
61  bool isEmpty() const override;
62  bool isIdle() const override;
63  int queueLength() const override;
64  void requestAbort() override;
65  void reschedule() override;
66  void shutDown() override;
67 
68  /** @brief Interface for the global queue factory. */
70  virtual ~GlobalQueueFactory()
71  {
72  }
73  virtual Queue *create(QObject *parent) = 0;
74  };
75  static void setGlobalQueueFactory(GlobalQueueFactory *factory);
76 
77 private:
78  class Private;
79  Private *const d;
80 };
81 
82 }
83 
84 #endif // THREADWEAVER_QUEUE_H
Interface for the global queue factory.
Definition: queue.h:69
QueueStream implements a stream based API to access ThreadWeaver queues.
Definition: queuestream.h:21
QueueSignals declares the Qt signals shared by the Queue and Weaver classes.
Definition: queuesignals.h:23
We use a State pattern to handle the system state in ThreadWeaver.
Definition: state.h:55
void suspend()
Queue implements a ThreadWeaver job queue.
Definition: queue.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Sep 22 2023 04:03:25 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.