ThreadWeaver

thread.h
1 /* -*- C++ -*-
2  This file is part of ThreadWeaver. It declares the Thread 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 THREADWEAVER_THREAD_H
10 #define THREADWEAVER_THREAD_H
11 
12 #include <QMutex>
13 #include <QThread>
14 
15 #include "jobpointer.h"
16 #include "threadweaver_export.h"
17 
18 namespace ThreadWeaver
19 {
20 class Job;
21 class Weaver;
22 
23 /** @brief Thread represents a worker thread in a Queue's inventory.
24  *
25  * Threads are created and managed by queues on demand. A Thread will try to retrieve and process
26  * jobs from the queue until it is told to exit. */
27 class THREADWEAVER_EXPORT Thread : public QThread
28 {
29  Q_OBJECT
30 public:
31  /** @brief Create a thread.
32  *
33  * @param parent the parent Weaver
34  */
35  explicit Thread(Weaver *parent = nullptr);
36 
37  /** The destructor. */
38  ~Thread() override;
39 
40  /** @brief The run method is reimplemented to execute jobs from the queue.
41  *
42  * Whenever the thread is idle, it will ask its Weaver parent for a Job to do. The Weaver will either return a Job or a null
43  * pointer. When a null pointer is returned, it tells the thread to exit.
44  */
45  void run() override;
46 
47  /** @brief Returns the thread id.
48  *
49  * This id marks the respective Thread object, and must therefore not be confused with, e.g., the pthread thread ID.
50  * The way threads are implemented and identified is platform specific. id() is the only way to uniquely identify a thread
51  * within ThreadWeaver.
52  */
53  unsigned int id() const;
54 
55  /** @brief Request the abortion of the job that is processed currently.
56  *
57  * If there is no current job, this method will do nothing, but can safely be called. It forwards the request to the
58  * current Job.
59  */
60  void requestAbort();
61 
62 Q_SIGNALS:
63 #if THREADWEAVER_ENABLE_DEPRECATED_SINCE(5, 80)
64  /**
65  *The thread has been started.
66  *
67  * @deprecated since 5.80, use the @c QThread::started() signal
68  */
69  THREADWEAVER_DEPRECATED_VERSION(5, 80, "Use the QThread::started() signal")
70  void started(ThreadWeaver::Thread *); // clazy:exclude=overloaded-signal
71 #endif
72 
73 private:
74  class Private;
75  Private *const d;
76 };
77 
78 }
79 
80 #endif
A Weaver manages worker threads.
Definition: weaver.h:34
Thread represents a worker thread in a Queue's inventory.
Definition: thread.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Feb 5 2023 04:09:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.