1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DCORE_TASK_P_H
5#define QT3DCORE_TASK_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/QRunnable>
19#include <QtCore/QSharedPointer>
20#include <QtCore/QThread>
21#include <QtCore/QtGlobal>
22
23#include <Qt3DCore/private/qaspectjobmanager_p.h>
24
25QT_BEGIN_NAMESPACE
26
27namespace Qt3DCore {
28
29class JobRunner;
30class DependencyHandler;
31class QThreadPooler;
32class QSystemInformationService;
33
34class RunnableInterface : public QRunnable
35{
36public:
37 enum class RunnableType {
38 AspectTask,
39 SyncTask
40 };
41
42 virtual ~RunnableInterface();
43
44 virtual bool isRequired() const = 0;
45 virtual void run() override = 0;
46
47 virtual int id() = 0;
48 virtual void setId(int id) = 0;
49
50 virtual void setReserved(bool reserved) = 0;
51 virtual bool reserved() = 0;
52
53 virtual void setPooler(QThreadPooler *pooler) = 0;
54
55 virtual RunnableType type() const = 0;
56};
57
58class AspectTaskRunnable : public RunnableInterface
59{
60public:
61 AspectTaskRunnable(QSystemInformationService *service);
62 ~AspectTaskRunnable();
63
64 bool isRequired() const override;
65 void run() override;
66
67 void setPooler(QThreadPooler *pooler) override { m_pooler = pooler; }
68
69 void setReserved(bool reserved) override { m_reserved = reserved; }
70 bool reserved() override { return m_reserved; }
71
72 int id() override { return m_id; }
73 void setId(int id) override { m_id = id; }
74
75 RunnableType type() const override { return RunnableType::AspectTask; }
76
77public:
78 QSharedPointer<QAspectJob> m_job;
79 QList<AspectTaskRunnable *> m_dependers;
80 int m_dependerCount = 0;
81
82private:
83 QSystemInformationService *m_service;
84 QThreadPooler *m_pooler;
85 int m_id; // For testing purposes for now
86 bool m_reserved;
87};
88
89class SyncTaskRunnable : public RunnableInterface
90{
91public:
92 explicit SyncTaskRunnable(QAbstractAspectJobManager::JobFunction func, void *arg,
93 QAtomicInt *atomicCount);
94 ~SyncTaskRunnable();
95
96 bool isRequired() const override;
97 void run() override;
98
99 void setPooler(QThreadPooler *pooler) override { m_pooler = pooler; }
100
101 void setReserved(bool reserved) override { m_reserved = reserved; }
102 bool reserved() override { return m_reserved; }
103
104 int id() override { return m_id; }
105 void setId(int id) override { m_id = id; }
106
107 RunnableType type() const override { return RunnableType::SyncTask; }
108
109private:
110 QAbstractAspectJobManager::JobFunction m_func;
111 void *m_arg;
112 QAtomicInt *m_atomicCount;
113
114 QThreadPooler *m_pooler;
115 bool m_reserved;
116
117 int m_id;
118};
119
120} // namespace Qt3DCore
121
122QT_END_NAMESPACE
123
124#endif // QT3DCORE_TASK_P_H
125
126

source code of qt3d/src/core/jobs/task_p.h