[app] Use separate task queue for the hashing task

This commit is contained in:
Slava Monich 2018-02-04 13:10:31 +03:00
parent 9e9d954722
commit fb23764d9c
4 changed files with 19 additions and 6 deletions

View file

@ -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();
}

View file

@ -142,6 +142,7 @@ private:
QImage iCoverImage;
shared_ptr<FormatPlugin> iFormatPlugin;
shared_ptr<BooksTaskQueue> iTaskQueue;
shared_ptr<BooksTaskQueue> iHashTaskQueue;
BooksSaveTimer* iSaveTimer;
CoverTask* iCoverTask;
HashTask* iHashTask;

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2015-2018 Jolla Ltd.
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
*
* 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<BooksTaskQueue> gDefaultQueue;
static weak_ptr<BooksTaskQueue> gScaleQueue;
static weak_ptr<BooksTaskQueue> 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<BooksTaskQueue> 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<BooksTaskQueue> get(weak_ptr<BooksTaskQueue>* aQueue,
@ -70,6 +73,7 @@ public:
weak_ptr<BooksTaskQueue> BooksTaskQueue::Private::gDefaultQueue;
weak_ptr<BooksTaskQueue> BooksTaskQueue::Private::gScaleQueue;
weak_ptr<BooksTaskQueue> BooksTaskQueue::Private::gHashQueue;
shared_ptr<BooksTaskQueue> BooksTaskQueue::defaultQueue()
{
@ -81,6 +85,11 @@ shared_ptr<BooksTaskQueue> BooksTaskQueue::scaleQueue()
return Private::get(&Private::gScaleQueue, Private::newScaleQueue);
}
shared_ptr<BooksTaskQueue> BooksTaskQueue::hashQueue()
{
return Private::get(&Private::gHashQueue, Private::newHashQueue);
}
void BooksTaskQueue::waitForDone(int aMsecs)
{
Private::waitForDone(aMsecs);

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2015-2018 Jolla Ltd.
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
*
* 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<BooksTaskQueue> defaultQueue();
static shared_ptr<BooksTaskQueue> scaleQueue();
static shared_ptr<BooksTaskQueue> hashQueue();
static void waitForDone(int aMsecs = -1);
void submit(BooksTask* aTask);