mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Merge pull request #12412 from samcake/blue
Introduce task abort feature for early exit of task branch
This commit is contained in:
commit
f809862870
3 changed files with 76 additions and 4 deletions
|
@ -453,6 +453,10 @@ void SelectionToHighlight::run(const render::RenderContextPointer& renderContext
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numLayers == 0) {
|
||||
renderContext->taskFlow.abortTask();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtractSelectionName::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) {
|
||||
|
|
35
libraries/task/src/task/Task.cpp
Normal file
35
libraries/task/src/task/Task.cpp
Normal file
|
@ -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 TaskFlow::reset() {
|
||||
_doAbortTask = false;
|
||||
}
|
||||
|
||||
void TaskFlow::abortTask() {
|
||||
_doAbortTask = true;
|
||||
}
|
||||
|
||||
bool TaskFlow::doAbortTask() const {
|
||||
return _doAbortTask;
|
||||
}
|
||||
|
||||
|
|
@ -27,15 +27,44 @@ template <class JC> class JobT;
|
|||
template <class JC> 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<T> class
|
||||
TaskFlow() = default;
|
||||
~TaskFlow() = default;
|
||||
void reset();
|
||||
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) : profileCategory(category) {
|
||||
assert(&category);
|
||||
}
|
||||
virtual ~JobContext() {}
|
||||
JobContext(const QLoggingCategory& category);
|
||||
virtual ~JobContext();
|
||||
|
||||
std::shared_ptr<JobConfig> jobConfig { nullptr };
|
||||
const QLoggingCategory& profileCategory;
|
||||
|
||||
// Task flow control
|
||||
TaskFlow taskFlow{};
|
||||
|
||||
protected:
|
||||
};
|
||||
using JobContextPointer = std::shared_ptr<JobContext>;
|
||||
|
||||
|
@ -308,6 +337,10 @@ public:
|
|||
if (config->alwaysEnabled || config->enabled) {
|
||||
for (auto job : TaskConcept::_jobs) {
|
||||
job.run(jobContext);
|
||||
if (jobContext->taskFlow.doAbortTask()) {
|
||||
jobContext->taskFlow.reset();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue