From fb23764d9ca4a35cba53a62fcf0d527b32fc1b8c Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 4 Feb 2018 13:10:31 +0300 Subject: [PATCH] [app] Use separate task queue for the hashing task --- app/src/BooksBook.cpp | 4 +++- app/src/BooksBook.h | 1 + app/src/BooksTaskQueue.cpp | 13 +++++++++++-- app/src/BooksTaskQueue.h | 7 ++++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/BooksBook.cpp b/app/src/BooksBook.cpp index da47c38..69558ec 100644 --- a/app/src/BooksBook.cpp +++ b/app/src/BooksBook.cpp @@ -386,9 +386,10 @@ BooksBook::BooksBook(const BooksStorage& aStorage, QString aRelativePath, } if (iHash.isEmpty()) { HDEBUG("need to calculate hash for" << qPrintable(iPath)); + iHashTaskQueue = BooksTaskQueue::hashQueue(); iHashTask = new HashTask(iPath, thread()); connect(iHashTask, SIGNAL(done()), SLOT(onHashTaskDone())); - iTaskQueue->submit(iHashTask); + iHashTaskQueue->submit(iHashTask); } // Refcounted BooksBook objects are managed by C++ code QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); @@ -602,6 +603,7 @@ void BooksBook::onHashTaskDone() HDEBUG(QString(iHash.toHex())); iHashTask->release(this); iHashTask = NULL; + iHashTaskQueue.reset(); Q_EMIT hashChanged(); } diff --git a/app/src/BooksBook.h b/app/src/BooksBook.h index d7cdbf9..cc463b5 100644 --- a/app/src/BooksBook.h +++ b/app/src/BooksBook.h @@ -142,6 +142,7 @@ private: QImage iCoverImage; shared_ptr iFormatPlugin; shared_ptr iTaskQueue; + shared_ptr iHashTaskQueue; BooksSaveTimer* iSaveTimer; CoverTask* iCoverTask; HashTask* iHashTask; diff --git a/app/src/BooksTaskQueue.cpp b/app/src/BooksTaskQueue.cpp index 0a7569f..aeeb897 100644 --- a/app/src/BooksTaskQueue.cpp +++ b/app/src/BooksTaskQueue.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015-2017 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2015-2018 Jolla Ltd. + * Copyright (C) 2015-2018 Slava Monich * * You may use this file under the terms of the BSD license as follows: * @@ -40,9 +40,11 @@ class BooksTaskQueue::Private { public: static weak_ptr gDefaultQueue; static weak_ptr gScaleQueue; + static weak_ptr gHashQueue; static BooksTaskQueue* newDefaultQueue() { return new BooksTaskQueue(1); } static BooksTaskQueue* newScaleQueue() { return new BooksTaskQueue(2); } + static BooksTaskQueue* newHashQueue() { return new BooksTaskQueue(1); } static void waitForDone(shared_ptr aQueue, int aMsecs) { if (!aQueue.isNull()) { @@ -53,6 +55,7 @@ public: static void waitForDone(int aMsecs) { waitForDone(gDefaultQueue, aMsecs); waitForDone(gScaleQueue, aMsecs); + waitForDone(gHashQueue, aMsecs); } static shared_ptr get(weak_ptr* aQueue, @@ -70,6 +73,7 @@ public: weak_ptr BooksTaskQueue::Private::gDefaultQueue; weak_ptr BooksTaskQueue::Private::gScaleQueue; +weak_ptr BooksTaskQueue::Private::gHashQueue; shared_ptr BooksTaskQueue::defaultQueue() { @@ -81,6 +85,11 @@ shared_ptr BooksTaskQueue::scaleQueue() return Private::get(&Private::gScaleQueue, Private::newScaleQueue); } +shared_ptr BooksTaskQueue::hashQueue() +{ + return Private::get(&Private::gHashQueue, Private::newHashQueue); +} + void BooksTaskQueue::waitForDone(int aMsecs) { Private::waitForDone(aMsecs); diff --git a/app/src/BooksTaskQueue.h b/app/src/BooksTaskQueue.h index 6c3f5a2..730c63c 100644 --- a/app/src/BooksTaskQueue.h +++ b/app/src/BooksTaskQueue.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2015-2018 Jolla Ltd. + * Copyright (C) 2015-2018 Slava Monich * * You may use this file under the terms of the BSD license as follows: * @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * * Neither the name of Nemo Mobile nor the names of its contributors + * * Neither the name of Jolla Ltd nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * @@ -47,6 +47,7 @@ class BooksTaskQueue public: static shared_ptr defaultQueue(); static shared_ptr scaleQueue(); + static shared_ptr hashQueue(); static void waitForDone(int aMsecs = -1); void submit(BooksTask* aTask);