[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:
parent
a1adc666aa
commit
a48fe1d0e4
3 changed files with 23 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Jolla Ltd.
|
* Copyright (C) 2015-2017 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Contact: Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* 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
|
* notice, this list of conditions and the following disclaimer in
|
||||||
* the documentation and/or other materials provided with the
|
* the documentation and/or other materials provided with the
|
||||||
* distribution.
|
* 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
|
* may be used to endorse or promote products derived from this
|
||||||
* software without specific prior written permission.
|
* software without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -40,8 +40,9 @@
|
||||||
|
|
||||||
BooksTask::BooksTask() :
|
BooksTask::BooksTask() :
|
||||||
iAboutToQuit(false),
|
iAboutToQuit(false),
|
||||||
iReleased(false),
|
iSubmitted(false),
|
||||||
iStarted(false),
|
iStarted(false),
|
||||||
|
iReleased(false),
|
||||||
iDone(false)
|
iDone(false)
|
||||||
{
|
{
|
||||||
setAutoDelete(false);
|
setAutoDelete(false);
|
||||||
|
@ -53,20 +54,22 @@ BooksTask::BooksTask() :
|
||||||
BooksTask::~BooksTask()
|
BooksTask::~BooksTask()
|
||||||
{
|
{
|
||||||
HASSERT(iReleased);
|
HASSERT(iReleased);
|
||||||
if (iStarted) wait();
|
if (iSubmitted) wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BooksTask::release(QObject* aHandler)
|
void BooksTask::release(QObject* aHandler)
|
||||||
{
|
{
|
||||||
disconnect(aHandler);
|
disconnect(aHandler);
|
||||||
iReleased = true;
|
iReleased = true;
|
||||||
if (!iStarted || iDone) {
|
if (!iSubmitted || iDone) {
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BooksTask::run()
|
void BooksTask::run()
|
||||||
{
|
{
|
||||||
|
HASSERT(!iStarted);
|
||||||
|
iStarted = true;
|
||||||
performTask();
|
performTask();
|
||||||
Q_EMIT runFinished();
|
Q_EMIT runFinished();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Jolla Ltd.
|
* Copyright (C) 2015-2017 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Contact: Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* 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
|
* notice, this list of conditions and the following disclaimer in
|
||||||
* the documentation and/or other materials provided with the
|
* the documentation and/or other materials provided with the
|
||||||
* distribution.
|
* 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
|
* may be used to endorse or promote products derived from this
|
||||||
* software without specific prior written permission.
|
* software without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -50,10 +50,11 @@ protected:
|
||||||
public:
|
public:
|
||||||
virtual ~BooksTask();
|
virtual ~BooksTask();
|
||||||
|
|
||||||
|
bool isStarted() const;
|
||||||
void release(QObject* aHandler);
|
void release(QObject* aHandler);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool isCanceled() const { return iReleased || iAboutToQuit; }
|
bool isCanceled() const;
|
||||||
|
|
||||||
virtual void run();
|
virtual void run();
|
||||||
virtual void performTask() = 0;
|
virtual void performTask() = 0;
|
||||||
|
@ -68,9 +69,15 @@ private Q_SLOTS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool iAboutToQuit;
|
bool iAboutToQuit;
|
||||||
bool iReleased;
|
bool iSubmitted;
|
||||||
bool iStarted;
|
bool iStarted;
|
||||||
|
bool iReleased;
|
||||||
bool iDone;
|
bool iDone;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool BooksTask::isStarted() const
|
||||||
|
{ return iStarted; }
|
||||||
|
inline bool BooksTask::isCanceled() const
|
||||||
|
{ return iReleased || iAboutToQuit; }
|
||||||
|
|
||||||
#endif // BOOKS_TASK_H
|
#endif // BOOKS_TASK_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Jolla Ltd.
|
* Copyright (C) 2015-2017 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Contact: Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* 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
|
* notice, this list of conditions and the following disclaimer in
|
||||||
* the documentation and/or other materials provided with the
|
* the documentation and/or other materials provided with the
|
||||||
* distribution.
|
* 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
|
* may be used to endorse or promote products derived from this
|
||||||
* software without specific prior written permission.
|
* software without specific prior written permission.
|
||||||
*
|
*
|
||||||
|
@ -103,8 +103,8 @@ BooksTaskQueue::~BooksTaskQueue()
|
||||||
|
|
||||||
void BooksTaskQueue::submit(BooksTask* aTask)
|
void BooksTaskQueue::submit(BooksTask* aTask)
|
||||||
{
|
{
|
||||||
HASSERT(!aTask->iStarted);
|
HASSERT(!aTask->iSubmitted);
|
||||||
aTask->iStarted = true;
|
aTask->iSubmitted = true;
|
||||||
iPool->start(aTask);
|
iPool->start(aTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue