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_QTHREADPOOLER_H |
5 | #define QT3DCORE_QTHREADPOOLER_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/QFuture> |
19 | #include <QtCore/QFutureInterface> |
20 | #include <QtCore/QObject> |
21 | #include <QtCore/QSharedPointer> |
22 | #include <QtCore/QThreadPool> |
23 | |
24 | #include <Qt3DCore/private/qaspectjob_p.h> |
25 | #include <Qt3DCore/private/task_p.h> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | namespace Qt3DCore { |
30 | |
31 | class Q_3DCORE_PRIVATE_EXPORT QThreadPooler : public QObject |
32 | { |
33 | Q_OBJECT |
34 | |
35 | public: |
36 | explicit QThreadPooler(QObject *parent = nullptr); |
37 | ~QThreadPooler(); |
38 | |
39 | QFuture<void> mapDependables(QList<RunnableInterface *> &taskQueue); |
40 | int waitForAllJobs(); |
41 | void taskFinished(RunnableInterface *task); |
42 | QFuture<void> future(); |
43 | |
44 | private: |
45 | void enqueueTasks(const QList<RunnableInterface *> &tasks); |
46 | void skipTask(RunnableInterface *task); |
47 | void enqueueDepencies(RunnableInterface *task); |
48 | void acquire(int add); |
49 | void release(); |
50 | int currentCount() const; |
51 | |
52 | private: |
53 | QFutureInterface<void> *m_futureInterface; |
54 | QMutex m_mutex; |
55 | QAtomicInt m_taskCount; |
56 | QThreadPool *m_threadPool; |
57 | int m_totalRunJobs; |
58 | }; |
59 | |
60 | } // namespace Qt3DCore |
61 | |
62 | QT_END_NAMESPACE |
63 | |
64 | #endif // QT3DCORE_QTHREADPOOLER_H |
65 | |