summaryrefslogtreecommitdiffstats
path: root/src/core/jobs/qthreadpooler.cpp
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@qt.io>2017-08-25 10:14:49 +0200
committerLars Knoll <lars.knoll@qt.io>2017-09-06 18:10:13 +0000
commitd5926d26e2b39920acd1ecd22a33bc65c3cf49ad (patch)
treee1d244723c345763c04eddc7bc81d38fae3d2029 /src/core/jobs/qthreadpooler.cpp
parente9e3208dd7c2e2f755948b1838faa94c2802cc30 (diff)
Improve dependency look-up
Simplify the dependency look-up by moving the dependers directly into the dependee runnable, each task is then responsible for updating their dependers and queue them up when they are free to be run. Change-Id: I96295d47cecd507a864965e1fb65f2ff9af68111 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/core/jobs/qthreadpooler.cpp')
-rw-r--r--src/core/jobs/qthreadpooler.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/core/jobs/qthreadpooler.cpp b/src/core/jobs/qthreadpooler.cpp
index 9985e4cee..3c9834418 100644
--- a/src/core/jobs/qthreadpooler.cpp
+++ b/src/core/jobs/qthreadpooler.cpp
@@ -48,8 +48,6 @@
#include <QtCore/QCoreApplication>
#endif
-#include <Qt3DCore/private/dependencyhandler_p.h>
-
QT_BEGIN_NAMESPACE
namespace Qt3DCore {
@@ -62,7 +60,6 @@ QThreadPooler::QThreadPooler(QObject *parent)
: QObject(parent)
, m_futureInterface(nullptr)
, m_mutex()
- , m_dependencyHandler(nullptr)
, m_taskCount(0)
{
// Ensures that threads will never be recycled
@@ -79,12 +76,6 @@ QThreadPooler::~QThreadPooler()
locker.unlock();
}
-void QThreadPooler::setDependencyHandler(DependencyHandler *handler)
-{
- m_dependencyHandler = handler;
- m_dependencyHandler->setMutex(&m_mutex);
-}
-
void QThreadPooler::enqueueTasks(const QVector<RunnableInterface *> &tasks)
{
// The caller have to set the mutex
@@ -92,7 +83,14 @@ void QThreadPooler::enqueueTasks(const QVector<RunnableInterface *> &tasks)
for (QVector<RunnableInterface *>::const_iterator it = tasks.cbegin();
it != end; ++it) {
- if (!m_dependencyHandler->hasDependency((*it)) && !(*it)->reserved()) {
+
+ // Only AspectTaskRunnables are checked for dependencies.
+ static const auto hasDependencies = [](RunnableInterface *task) -> bool {
+ return (task->type() == RunnableInterface::RunnableType::AspectTask)
+ && (static_cast<AspectTaskRunnable *>(task)->m_dependerCount > 0);
+ };
+
+ if (!hasDependencies(*it) && !(*it)->reserved()) {
(*it)->setReserved(true);
(*it)->setPooler(this);
m_threadPool.start((*it));
@@ -106,10 +104,19 @@ void QThreadPooler::taskFinished(RunnableInterface *task)
release();
- if (task->dependencyHandler()) {
- const QVector<RunnableInterface *> freedTasks = m_dependencyHandler->freeDependencies(task);
- if (!freedTasks.empty())
- enqueueTasks(freedTasks);
+ if (task->type() == RunnableInterface::RunnableType::AspectTask) {
+ AspectTaskRunnable *aspectTask = static_cast<AspectTaskRunnable *>(task);
+ const auto &dependers = aspectTask->m_dependers;
+ for (auto it = dependers.begin(); it != dependers.end(); ++it) {
+ aspectTask = static_cast<AspectTaskRunnable *>(*it);
+ if (--aspectTask->m_dependerCount == 0) {
+ if (!aspectTask->reserved()) {
+ aspectTask->setReserved(true);
+ aspectTask->setPooler(this);
+ m_threadPool.start(aspectTask);
+ }
+ }
+ }
}
if (currentCount() == 0) {