Add a way to early abort a task from a Job, apply that to the highlight effect to shave unecessary work

This commit is contained in:
samcake 2018-02-15 11:24:20 -08:00
parent 246ac25d0a
commit b21b98c810
3 changed files with 23 additions and 13 deletions

View file

@ -455,7 +455,7 @@ void SelectionToHighlight::run(const render::RenderContextPointer& renderContext
} }
if (numLayers == 0) { if (numLayers == 0) {
renderContext->abortTask(); renderContext->taskFlow.abortTask();
} }
} }

View file

@ -20,15 +20,15 @@ JobContext::JobContext(const QLoggingCategory& category) :
JobContext::~JobContext() { JobContext::~JobContext() {
} }
void JobContext::resetTaskFlow() { void TaskFlow::reset() {
_doAbortTask = false; _doAbortTask = false;
} }
void JobContext::abortTask() { void TaskFlow::abortTask() {
_doAbortTask = true; _doAbortTask = true;
} }
bool JobContext::doAbortTask() const { bool TaskFlow::doAbortTask() const {
return _doAbortTask; return _doAbortTask;
} }

View file

@ -27,6 +27,21 @@ template <class JC> class JobT;
template <class JC> class TaskT; template <class JC> class TaskT;
class JobNoIO {}; class JobNoIO {};
class TaskFlow {
public:
TaskFlow() = default;
~TaskFlow() = default;
// called after each job
void reset();
void abortTask();
bool doAbortTask() const;
protected:
bool _doAbortTask{ false };
};
class JobContext { class JobContext {
public: public:
JobContext(const QLoggingCategory& category); JobContext(const QLoggingCategory& category);
@ -35,15 +50,10 @@ public:
std::shared_ptr<JobConfig> jobConfig { nullptr }; std::shared_ptr<JobConfig> jobConfig { nullptr };
const QLoggingCategory& profileCategory; const QLoggingCategory& profileCategory;
// control flow commands // Task flow control
void resetTaskFlow(); TaskFlow taskFlow{};
void abortTask();
// Check command flow
bool doAbortTask() const;
protected: protected:
bool _doAbortTask{ false };
}; };
using JobContextPointer = std::shared_ptr<JobContext>; using JobContextPointer = std::shared_ptr<JobContext>;
@ -316,8 +326,8 @@ public:
if (config->alwaysEnabled || config->enabled) { if (config->alwaysEnabled || config->enabled) {
for (auto job : TaskConcept::_jobs) { for (auto job : TaskConcept::_jobs) {
job.run(jobContext); job.run(jobContext);
if (jobContext->doAbortTask()) { if (jobContext->taskFlow.doAbortTask()) {
jobContext->resetTaskFlow(); jobContext->taskFlow.reset();
return; return;
} }
} }