From 246ac25d0ab0b6fc5afdc48048e31d5d085f9d9b Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 14 Feb 2018 17:36:46 -0800 Subject: [PATCH 1/3] Introducing a way to abort a task from one of its job, using it to skip highlight tasks if nothing to highlight --- .../render-utils/src/HighlightEffect.cpp | 4 +++ libraries/task/src/task/Task.cpp | 35 +++++++++++++++++++ libraries/task/src/task/Task.h | 20 ++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 libraries/task/src/task/Task.cpp diff --git a/libraries/render-utils/src/HighlightEffect.cpp b/libraries/render-utils/src/HighlightEffect.cpp index 9501a74d52..de13188733 100644 --- a/libraries/render-utils/src/HighlightEffect.cpp +++ b/libraries/render-utils/src/HighlightEffect.cpp @@ -453,6 +453,10 @@ void SelectionToHighlight::run(const render::RenderContextPointer& renderContext } } } + + if (numLayers == 0) { + renderContext->abortTask(); + } } void ExtractSelectionName::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { diff --git a/libraries/task/src/task/Task.cpp b/libraries/task/src/task/Task.cpp new file mode 100644 index 0000000000..bb65f15b7c --- /dev/null +++ b/libraries/task/src/task/Task.cpp @@ -0,0 +1,35 @@ +// +// Task.cpp +// task/src/task +// +// Created by Sam Gateau on 2/14/2018. +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "Task.h" + +using namespace task; + +JobContext::JobContext(const QLoggingCategory& category) : + profileCategory(category) { + assert(&category); +} + +JobContext::~JobContext() { +} + +void JobContext::resetTaskFlow() { + _doAbortTask = false; +} + +void JobContext::abortTask() { + _doAbortTask = true; +} + +bool JobContext::doAbortTask() const { + return _doAbortTask; +} + + diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index b75f6d7321..1f1fb79ee1 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -29,13 +29,21 @@ class JobNoIO {}; class JobContext { public: - JobContext(const QLoggingCategory& category) : profileCategory(category) { - assert(&category); - } - virtual ~JobContext() {} + JobContext(const QLoggingCategory& category); + virtual ~JobContext(); std::shared_ptr jobConfig { nullptr }; const QLoggingCategory& profileCategory; + + // control flow commands + void resetTaskFlow(); + void abortTask(); + + // Check command flow + bool doAbortTask() const; + +protected: + bool _doAbortTask{ false }; }; using JobContextPointer = std::shared_ptr; @@ -308,6 +316,10 @@ public: if (config->alwaysEnabled || config->enabled) { for (auto job : TaskConcept::_jobs) { job.run(jobContext); + if (jobContext->doAbortTask()) { + jobContext->resetTaskFlow(); + return; + } } } } From b21b98c81066a85be556dec87a238650729dfe00 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 15 Feb 2018 11:24:20 -0800 Subject: [PATCH 2/3] Add a way to early abort a task from a Job, apply that to the highlight effect to shave unecessary work --- .../render-utils/src/HighlightEffect.cpp | 2 +- libraries/task/src/task/Task.cpp | 6 ++-- libraries/task/src/task/Task.h | 28 +++++++++++++------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/libraries/render-utils/src/HighlightEffect.cpp b/libraries/render-utils/src/HighlightEffect.cpp index de13188733..0bf8e7fa71 100644 --- a/libraries/render-utils/src/HighlightEffect.cpp +++ b/libraries/render-utils/src/HighlightEffect.cpp @@ -455,7 +455,7 @@ void SelectionToHighlight::run(const render::RenderContextPointer& renderContext } if (numLayers == 0) { - renderContext->abortTask(); + renderContext->taskFlow.abortTask(); } } diff --git a/libraries/task/src/task/Task.cpp b/libraries/task/src/task/Task.cpp index bb65f15b7c..621d77d7bf 100644 --- a/libraries/task/src/task/Task.cpp +++ b/libraries/task/src/task/Task.cpp @@ -20,15 +20,15 @@ JobContext::JobContext(const QLoggingCategory& category) : JobContext::~JobContext() { } -void JobContext::resetTaskFlow() { +void TaskFlow::reset() { _doAbortTask = false; } -void JobContext::abortTask() { +void TaskFlow::abortTask() { _doAbortTask = true; } -bool JobContext::doAbortTask() const { +bool TaskFlow::doAbortTask() const { return _doAbortTask; } diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index 1f1fb79ee1..34cdbb5439 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -27,6 +27,21 @@ template class JobT; template class TaskT; 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 { public: JobContext(const QLoggingCategory& category); @@ -35,15 +50,10 @@ public: std::shared_ptr jobConfig { nullptr }; const QLoggingCategory& profileCategory; - // control flow commands - void resetTaskFlow(); - void abortTask(); - - // Check command flow - bool doAbortTask() const; + // Task flow control + TaskFlow taskFlow{}; protected: - bool _doAbortTask{ false }; }; using JobContextPointer = std::shared_ptr; @@ -316,8 +326,8 @@ public: if (config->alwaysEnabled || config->enabled) { for (auto job : TaskConcept::_jobs) { job.run(jobContext); - if (jobContext->doAbortTask()) { - jobContext->resetTaskFlow(); + if (jobContext->taskFlow.doAbortTask()) { + jobContext->taskFlow.reset(); return; } } From c70b655fbc5a170e180e9d99f800fb39d73c6af2 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 15 Feb 2018 11:55:16 -0800 Subject: [PATCH 3/3] A bit more explanations to the Task Flow class --- libraries/task/src/task/Task.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index 34cdbb5439..08df55dddd 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -27,21 +27,32 @@ template class JobT; template class TaskT; class JobNoIO {}; +// Task Flow control class is a simple per value object used to communicate flow control commands trhough the graph of tasks. +// From within the Job::Run function, you can access it from the JobCOntext and issue commands which will be picked up by the Task calling for the Job run. +// This is first introduced to provide a way to abort all the work from within a task job. see the "abortTask" call class TaskFlow { public: + // A job that wants to abort the rest of the other jobs execution in a task would issue that call "abortTask" and let the task early exit for this run. + // All the varyings produced by the aborted branch of jobs are left unmodified. + void abortTask(); + + // called by the task::run to perform flow control + // This should be considered private but still need to be accessible from the Task class TaskFlow() = default; ~TaskFlow() = default; - - // called after each job void reset(); - - void abortTask(); bool doAbortTask() const; protected: bool _doAbortTask{ false }; }; +// JobContext class is the base calss for the context object which is passed through all the Job::run calls thoughout the graph of jobs +// It is used to communicate to the job::run its context and various state information the job relies on. +// It specifically provide access to: +// - The taskFlow object allowing for messaging control flow commands from within a Job::run +// - The current Config object attached to the Job::run currently called. +// The JobContext can be derived to add more global state to it that Jobs can access class JobContext { public: JobContext(const QLoggingCategory& category);