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 <mirko@kde.org>
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
18namespace ThreadWeaver
19{
20class Job;
21class 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. */
27class THREADWEAVER_EXPORT Thread : public QThread
28{
29 Q_OBJECT
30public:
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
62private:
63 class Private;
64 Private *const d;
65};
66
67}
68
69#endif
Thread represents a worker thread in a Queue's inventory.
Definition thread.h:28
A Weaver manages worker threads.
Definition weaver.h:35
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.