[app] Added BooksTask::isStarted() method

Allows the owner of the task to check whether the task has actually
started to execute. This is a one-way flag, not synchronized (and
doesn't need to be).
This commit is contained in:
Slava Monich 2017-09-07 18:23:28 +03:00
parent a1adc666aa
commit a48fe1d0e4
3 changed files with 23 additions and 13 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (C) 2015-2017 Jolla Ltd.
* Contact: 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.
*
@ -40,8 +40,9 @@
BooksTask::BooksTask() :
iAboutToQuit(false),
iReleased(false),
iSubmitted(false),
iStarted(false),
iReleased(false),
iDone(false)
{
setAutoDelete(false);
@ -53,20 +54,22 @@ BooksTask::BooksTask() :
BooksTask::~BooksTask()
{
HASSERT(iReleased);
if (iStarted) wait();
if (iSubmitted) wait();
}
void BooksTask::release(QObject* aHandler)
{
disconnect(aHandler);
iReleased = true;
if (!iStarted || iDone) {
if (!iSubmitted || iDone) {
delete this;
}
}
void BooksTask::run()
{
HASSERT(!iStarted);
iStarted = true;
performTask();
Q_EMIT runFinished();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (C) 2015-2017 Jolla Ltd.
* Contact: 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.
*
@ -50,10 +50,11 @@ protected:
public:
virtual ~BooksTask();
bool isStarted() const;
void release(QObject* aHandler);
protected:
bool isCanceled() const { return iReleased || iAboutToQuit; }
bool isCanceled() const;
virtual void run();
virtual void performTask() = 0;
@ -68,9 +69,15 @@ private Q_SLOTS:
private:
bool iAboutToQuit;
bool iReleased;
bool iSubmitted;
bool iStarted;
bool iReleased;
bool iDone;
};
inline bool BooksTask::isStarted() const
{ return iStarted; }
inline bool BooksTask::isCanceled() const
{ return iReleased || iAboutToQuit; }
#endif // BOOKS_TASK_H

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (C) 2015-2017 Jolla Ltd.
* Contact: 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.
*
@ -103,8 +103,8 @@ BooksTaskQueue::~BooksTaskQueue()
void BooksTaskQueue::submit(BooksTask* aTask)
{
HASSERT(!aTask->iStarted);
aTask->iStarted = true;
HASSERT(!aTask->iSubmitted);
aTask->iSubmitted = true;
iPool->start(aTask);
}