Masterwork From Distant Lands
ActivePublic

Authored by dkazakov on Aug 9 2017, 9:52 AM.
diff --git a/libs/image/kis_regenerate_frame_stroke_strategy.cpp b/libs/image/kis_regenerate_frame_stroke_strategy.cpp
index efd43a4..6a555f8 100644
--- a/libs/image/kis_regenerate_frame_stroke_strategy.cpp
+++ b/libs/image/kis_regenerate_frame_stroke_strategy.cpp
@@ -241,6 +241,8 @@ QList<KisStrokeJobData*> KisRegenerateFrameStrokeStrategy::createJobsData(KisIma
const QRect cropRect = image->bounds();
QVector<QRect> rects = splitRectIntoPatches(image->bounds(), optimalPatchSize());
+ ENTER_FUNCTION() << ppVar(rects.size());
+
QList<KisStrokeJobData*> jobsData;
Q_FOREACH (const QRect &rc, rects) {
diff --git a/libs/image/kis_update_job_item.h b/libs/image/kis_update_job_item.h
index 39e534c..4ce9a49 100644
--- a/libs/image/kis_update_job_item.h
+++ b/libs/image/kis_update_job_item.h
@@ -53,27 +53,39 @@ public:
}
void run() override {
- if(m_exclusive) {
- m_exclusiveJobLock->lockForWrite();
- } else {
- m_exclusiveJobLock->lockForRead();
- }
+ if (!isRunning()) return;
- if(m_type == MERGE) {
- runMergeJob();
- } else {
- Q_ASSERT(m_type == STROKE || m_type == SPONTANEOUS);
- m_runnableJob->run();
- delete m_runnableJob;
- m_runnableJob = 0;
- }
+ int numRuns = 0;
- setDone();
+ while (isRunning()) {
+ if(m_exclusive) {
+ m_exclusiveJobLock->lockForWrite();
+ } else {
+ m_exclusiveJobLock->lockForRead();
+ }
+
+ if(m_type == MERGE) {
+ runMergeJob();
+ } else {
+ Q_ASSERT(m_type == STROKE || m_type == SPONTANEOUS);
+ m_runnableJob->run();
+ delete m_runnableJob;
+ m_runnableJob = 0;
+ }
+
+ setDone();
- emit sigDoSomeUsefulWork();
- emit sigJobFinished();
+ m_isExecuting.ref();
+ emit sigDoSomeUsefulWork();
+ emit sigJobFinished();
+ m_isExecuting.deref();
- m_exclusiveJobLock->unlock();
+ m_exclusiveJobLock->unlock();
+
+ numRuns++;
+ }
+
+ LEAVE_FUNCTION() << ppVar(numRuns);
}
inline void runMergeJob() {
@@ -136,6 +148,10 @@ public:
return m_changeRect;
}
+ inline bool isExecutingAtThread() const {
+ return m_isExecuting;
+ }
+
Q_SIGNALS:
void sigContinueUpdate(const QRect& rc);
void sigDoSomeUsefulWork();
@@ -198,6 +214,8 @@ private:
*/
QRect m_accessRect;
QRect m_changeRect;
+
+ QAtomicInt m_isExecuting;
};
diff --git a/libs/image/kis_updater_context.cpp b/libs/image/kis_updater_context.cpp
index b7b7d59..8bc9702 100644
--- a/libs/image/kis_updater_context.cpp
+++ b/libs/image/kis_updater_context.cpp
@@ -111,7 +111,10 @@ void KisUpdaterContext::addMergeJob(KisBaseRectsWalkerSP walker)
Q_ASSERT(jobIndex >= 0);
m_jobs[jobIndex]->setWalker(walker);
- m_threadPool.start(m_jobs[jobIndex]);
+
+ if (!m_jobs[jobIndex]->isExecutingAtThread()) {
+ m_threadPool.start(m_jobs[jobIndex]);
+ }
}
/**
@@ -134,7 +137,10 @@ void KisUpdaterContext::addStrokeJob(KisStrokeJob *strokeJob)
Q_ASSERT(jobIndex >= 0);
m_jobs[jobIndex]->setStrokeJob(strokeJob);
- m_threadPool.start(m_jobs[jobIndex]);
+
+ if (!m_jobs[jobIndex]->isExecutingAtThread()) {
+ m_threadPool.start(m_jobs[jobIndex]);
+ }
}
/**
@@ -157,7 +163,10 @@ void KisUpdaterContext::addSpontaneousJob(KisSpontaneousJob *spontaneousJob)
Q_ASSERT(jobIndex >= 0);
m_jobs[jobIndex]->setSpontaneousJob(spontaneousJob);
- m_threadPool.start(m_jobs[jobIndex]);
+
+ if (!m_jobs[jobIndex]->isExecutingAtThread()) {
+ m_threadPool.start(m_jobs[jobIndex]);
+ }
}
/**
dkazakov edited the content of this paste. (Show Details)Aug 9 2017, 9:52 AM
dkazakov changed the title of this paste from untitled to Masterwork From Distant Lands.
dkazakov updated the paste's language from autodetect to autodetect.