ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #07488
[Merge] lp:~ubuntu-docviewer-dev/ubuntu-docviewer-app/ubuntu-docviewer-app-re-fix into lp:ubuntu-docviewer-app
Stefano Verzegnassi has proposed merging lp:~ubuntu-docviewer-dev/ubuntu-docviewer-app/ubuntu-docviewer-app-re-fix into lp:ubuntu-docviewer-app.
Commit message:
RenderEngine: thread safety
Requested reviews:
Ubuntu Document Viewer Developers (ubuntu-docviewer-dev)
For more details, see:
https://code.launchpad.net/~ubuntu-docviewer-dev/ubuntu-docviewer-app/ubuntu-docviewer-app-re-fix/+merge/282877
RenderEngine: thread safety
--
Your team Ubuntu Document Viewer Developers is requested to review the proposed merge of lp:~ubuntu-docviewer-dev/ubuntu-docviewer-app/ubuntu-docviewer-app-re-fix into lp:ubuntu-docviewer-app.
=== modified file 'src/app/renderengine.cpp'
--- src/app/renderengine.cpp 2015-12-12 10:06:55 +0000
+++ src/app/renderengine.cpp 2016-01-17 21:17:02 +0000
@@ -28,7 +28,10 @@
auto task = m_queue.at(i);
if (task->id() == id) {
m_queue.removeAt(i);
- disposeLater(task);
+
+ if (!task->isOwnedByCaller())
+ disposeLater(task);
+
break;
}
}
@@ -38,16 +41,18 @@
{
m_activeTaskCount--;
+ if (!task->isOwnedByCaller())
+ disposeLater(task);
+
+ // Notify about result.
+ emit taskRenderFinished(task, img);
+
+ doNextTask();
+
if (!m_activeTaskCount) {
m_lastTask = nullptr;
doDispose();
}
-
- // Notify about result.
- emit taskRenderFinished(task, img);
-
- doNextTask();
- disposeLater(task);
}
void RenderEngine::disposeLater(AbstractRenderTask *task)
=== modified file 'src/app/renderengine.h'
--- src/app/renderengine.h 2015-12-12 10:06:55 +0000
+++ src/app/renderengine.h 2016-01-17 21:17:02 +0000
@@ -22,10 +22,12 @@
const int DefaultIdealThreadCount = 2;
-public:
+public Q_SLOTS:
void enqueueTask(AbstractRenderTask* task); // Takes ownership.
void dequeueTask(int id);
+public:
+
static RenderEngine* instance() {
if(!s_instance)
s_instance = new RenderEngine();
@@ -33,7 +35,7 @@
}
static int getNextId() {
- static int idCounter = 0xDEAD0000;
+ static QAtomicInt idCounter(0xDEAD0000);
return idCounter++;
}
=== modified file 'src/app/rendertask.h'
--- src/app/rendertask.h 2015-12-12 10:06:55 +0000
+++ src/app/rendertask.h 2016-01-17 21:17:02 +0000
@@ -21,6 +21,7 @@
class AbstractRenderTask
{
public:
+ AbstractRenderTask(): m_id(0), m_isOwnedByCaller(false) { }
virtual RenderTaskType type() { return RttUnknown; }
virtual QImage doWork() = 0 ;
virtual ~AbstractRenderTask() { }
@@ -29,8 +30,11 @@
int id() { return m_id; }
void setId(int i) { m_id = i; }
+ bool isOwnedByCaller() { return m_isOwnedByCaller; }
+ void setIsOwnedByCaller(bool v) { m_isOwnedByCaller = v; }
protected:
int m_id;
+ bool m_isOwnedByCaller;
};
Q_DECLARE_METATYPE(AbstractRenderTask*)
Follow ups