From 04c561d6a965b35df35d860c262ce0e8e4819b27 Mon Sep 17 00:00:00 2001 From: Charles Otto Date: Wed, 31 Jul 2013 13:34:27 -0400 Subject: [PATCH] Revert previous changes to thread pooling in br.cpp/meta.cpp --- app/br/br.cpp | 4 +--- openbr/plugins/meta.cpp | 39 +++++++++++++-------------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/app/br/br.cpp b/app/br/br.cpp index 8b6eee6..efd0483 100644 --- a/app/br/br.cpp +++ b/app/br/br.cpp @@ -235,10 +235,8 @@ int main(int argc, char *argv[]) { br_initialize(argc, argv); - QThreadPool separate; - separate.setMaxThreadCount(1); FakeMain *fakeMain = new FakeMain(argc, argv); - separate.start(fakeMain); + QThreadPool::globalInstance()->start(fakeMain); QCoreApplication::exec(); br_finalize(); diff --git a/openbr/plugins/meta.cpp b/openbr/plugins/meta.cpp index a77d315..7f827dc 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -597,26 +597,6 @@ static void _projectList(const Transform *transform, const TemplateList *src, Te transform->project(*src, *dst); } -class ProjectListJob : public QRunnable -{ -public: - ProjectListJob(Transform * _transform, const TemplateList * _src, TemplateList * _dst) - { - transform = _transform; - src = _src; - dst = _dst; - this->setAutoDelete(true); - } - - Transform * transform; - const TemplateList * src; - TemplateList * dst; - void run() - { - _projectList(transform, src, dst); - } -}; - class DistributeTemplateTransform : public MetaTransform { Q_OBJECT @@ -665,22 +645,29 @@ public: QList input_buffer; input_buffer.reserve(src.size()); + QFutureSynchronizer futures; + for (int i =0; i < src.size();i++) { input_buffer.append(TemplateList()); output_buffer.append(TemplateList()); } - + QList > temp; + temp.reserve(src.size()); for (int i=0; iparallelism) - QThreadPool::globalInstance()->start(new ProjectListJob(transform, &input_buffer[i], &output_buffer[i]), 0); + if (Globals->parallelism > 1) temp.append(QtConcurrent::run(_projectList, transform, &input_buffer[i], &output_buffer[i])); else _projectList(transform, &input_buffer[i], &output_buffer[i]); } + // We add the futures in reverse order, since in Qt 5.1 at least the + // waiting thread will wait on them in the order added (which for uniform priority + // threads is the order of execution), and we want the waiting thread to go in the opposite order + // so that it can steal runnables and do something besides wait. + for (int i = temp.size() - 1; i > 0; i--) { + futures.addFuture(temp[i]); + } - bool wait_res = QThreadPool::globalInstance()->waitForDone(); - if (!wait_res) - qDebug("global thread pool wait failed!"); + futures.waitForFinished(); for (int i=0; i