diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/CompiledGraph.cpp | 8 | ||||
-rw-r--r-- | src/server/CompiledGraph.hpp | 2 | ||||
-rw-r--r-- | src/server/Task.cpp | 40 | ||||
-rw-r--r-- | src/server/Task.hpp | 9 |
4 files changed, 30 insertions, 29 deletions
diff --git a/src/server/CompiledGraph.cpp b/src/server/CompiledGraph.cpp index 0d51f284..13d6690e 100644 --- a/src/server/CompiledGraph.cpp +++ b/src/server/CompiledGraph.cpp @@ -53,7 +53,7 @@ has_provider_with_many_dependants(BlockImpl* n) } CompiledGraph::CompiledGraph(GraphImpl* graph) - : _master(Task::Mode::SEQUENTIAL) + : _master(std::make_unique<Task>(Task::Mode::SEQUENTIAL)) { compile_graph(graph); } @@ -137,7 +137,7 @@ CompiledGraph::compile_graph(GraphImpl* graph) compile_block(b, seq, depth, predecessors); par.push_front(std::move(seq)); } - _master.push_front(std::move(par)); + _master->push_front(std::move(par)); blocks = predecessors; } @@ -253,7 +253,7 @@ CompiledGraph::compile_block(BlockImpl* n, void CompiledGraph::run(RunContext& context) { - _master.run(context); + _master->run(context); } void @@ -265,7 +265,7 @@ CompiledGraph::dump(const std::string& name) const sink("(compiled-graph "); sink(name); - _master.dump(sink, 2, false); + _master->dump(sink, 2, false); sink(")\n"); } diff --git a/src/server/CompiledGraph.hpp b/src/server/CompiledGraph.hpp index 833ae0c6..1a88e71f 100644 --- a/src/server/CompiledGraph.hpp +++ b/src/server/CompiledGraph.hpp @@ -70,7 +70,7 @@ private: size_t max_depth, BlockSet& k); - Task _master; + std::unique_ptr<Task> _master; }; inline MPtr<CompiledGraph> compile(Raul::Maid& maid, GraphImpl& graph) diff --git a/src/server/Task.cpp b/src/server/Task.cpp index c76c19ae..dd09e060 100644 --- a/src/server/Task.cpp +++ b/src/server/Task.cpp @@ -29,14 +29,14 @@ Task::run(RunContext& context) _block->process(context); break; case Mode::SEQUENTIAL: - for (auto& task : _children) { - task.run(context); + for (const auto& task : _children) { + task->run(context); } break; case Mode::PARALLEL: // Initialize (not) done state of sub-tasks - for (auto& task : _children) { - task.set_done(false); + for (const auto& task : _children) { + task->set_done(false); } // Grab the first sub-task @@ -64,7 +64,7 @@ Task::steal(RunContext& context) if (_mode == Mode::PARALLEL) { const unsigned i = _next++; if (i < _children.size()) { - return &_children[i]; + return _children[i].get(); } } @@ -82,7 +82,7 @@ Task::get_task(RunContext& context) while (true) { // Push done end index as forward as possible - while (_done_end < _children.size() && _children[_done_end].done()) { + while (_done_end < _children.size() && _children[_done_end]->done()) { ++_done_end; } @@ -103,31 +103,31 @@ Task::get_task(RunContext& context) } } -Task -Task::simplify(Task task) +std::unique_ptr<Task> +Task::simplify(std::unique_ptr<Task>&& task) { - if (task.mode() == Mode::SINGLE) { - return task; + if (task->mode() == Mode::SINGLE) { + return std::move(task); } - Task ret(task.mode()); - for (auto&& c : task._children) { + std::unique_ptr<Task> ret = std::make_unique<Task>(task->mode()); + for (auto&& c : task->_children) { auto child = simplify(std::move(c)); - if (!child.empty()) { - if (child.mode() == task.mode()) { + if (!child->empty()) { + if (child->mode() == task->mode()) { // Merge child into parent - for (auto&& grandchild : child._children) { - ret.append(std::move(grandchild)); + for (auto&& grandchild : child->_children) { + ret->append(std::move(grandchild)); } } else { // Add child task - ret.append(std::move(child)); + ret->append(std::move(child)); } } } - if (ret._children.size() == 1) { - return std::move(ret._children.front()); + if (ret->_children.size() == 1) { + return std::move(ret->_children.front()); } return ret; @@ -148,7 +148,7 @@ Task::dump(std::function<void (const std::string&)> sink, unsigned indent, bool } else { sink(((_mode == Mode::SEQUENTIAL) ? "(seq " : "(par ")); for (size_t i = 0; i < _children.size(); ++i) { - _children[i].dump(sink, indent + 5, i == 0); + _children[i]->dump(sink, indent + 5, i == 0); } sink(")"); } diff --git a/src/server/Task.hpp b/src/server/Task.hpp index 203627a1..3bcfbb40 100644 --- a/src/server/Task.hpp +++ b/src/server/Task.hpp @@ -21,6 +21,7 @@ #include <cassert> #include <deque> #include <functional> +#include <memory> #include <ostream> namespace Ingen { @@ -77,14 +78,14 @@ public: bool empty() const { return _mode != Mode::SINGLE && _children.empty(); } /** Simplify task expression. */ - static Task simplify(Task task); + static std::unique_ptr<Task> simplify(std::unique_ptr<Task>&& task); /** Steal a child task from this task (succeeds for PARALLEL only). */ Task* steal(RunContext& context); /** Prepend a child to this task. */ void push_front(Task&& task) { - _children.emplace_front(std::move(task)); + _children.emplace_front(std::make_unique<Task>(std::move(task))); } Mode mode() const { return _mode; } @@ -94,14 +95,14 @@ public: void set_done(bool done) { _done = done; } private: - typedef std::deque<Task> Children; + typedef std::deque<std::unique_ptr<Task>> Children; Task(const Task&) = delete; Task& operator=(const Task&) = delete; Task* get_task(RunContext& context); - void append(Task t) { + void append(std::unique_ptr<Task>&& t) { _children.emplace_back(std::move(t)); } |