ThreadWeaver

queue.h
1/* -*- C++ -*-
2 The Queue class in ThreadWeaver.
3
4 SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org>
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
17namespace ThreadWeaver
18{
19class Job;
20class 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 */
35class THREADWEAVER_EXPORT Queue : public QueueSignals
36{
37 Q_OBJECT
38public:
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 QList<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
77private:
78 class Private;
79 Private *const d;
80};
81
82}
83
84#endif // THREADWEAVER_QUEUE_H
QueueSignals declares the Qt signals shared by the Queue and Weaver classes.
QueueStream implements a stream based API to access ThreadWeaver queues.
Definition queuestream.h:22
Queue implements a ThreadWeaver job queue.
Definition queue.h:36
We use a State pattern to handle the system state in ThreadWeaver.
Definition state.h:56
void suspend()
Interface for the global queue factory.
Definition queue.h:69
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:58:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.