diff options
Diffstat (limited to 'src/server/CompiledGraph.cpp')
-rw-r--r-- | src/server/CompiledGraph.cpp | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/src/server/CompiledGraph.cpp b/src/server/CompiledGraph.cpp index 9efed05f..89fc8843 100644 --- a/src/server/CompiledGraph.cpp +++ b/src/server/CompiledGraph.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2015-2017 David Robillard <http://drobilla.net/> + Copyright 2015-2024 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -21,56 +21,64 @@ #include "GraphImpl.hpp" #include "ThreadManager.hpp" -#include "ingen/ColorContext.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/Log.hpp" -#include "ingen/World.hpp" +#include <ingen/Atom.hpp> +#include <ingen/ColorContext.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/Log.hpp> +#include <ingen/World.hpp> +#include <raul/Path.hpp> + +#include <boost/intrusive/slist.hpp> #include <algorithm> #include <cassert> #include <cstdint> #include <cstdio> +#include <exception> +#include <functional> #include <limits> +#include <memory> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { /** Graph contains ambiguous feedback with no delay nodes. */ -class FeedbackException : public std::exception { +class FeedbackException : public std::exception +{ public: - explicit FeedbackException(const BlockImpl* node, - const BlockImpl* root = nullptr) - : node(node), root(root) + explicit FeedbackException(const BlockImpl* n) + : node(n) {} - const BlockImpl* node; - const BlockImpl* root; + FeedbackException(const BlockImpl* n, const BlockImpl* r) + : node(n), root(r) + {} + + const BlockImpl* node = nullptr; + const BlockImpl* root = nullptr; }; static bool -has_provider_with_many_dependants(BlockImpl* n) +has_provider_with_many_dependants(const BlockImpl* n) { - for (BlockImpl* p : n->providers()) { - if (p->dependants().size() > 1) { - return true; - } - } - - return false; + return std::any_of(n->providers().begin(), + n->providers().end(), + [](const auto* p) { + return p->dependants().size() > 1; + }); } CompiledGraph::CompiledGraph(GraphImpl* graph) - : _master(std::unique_ptr<Task>(new Task(Task::Mode::SEQUENTIAL))) + : _master{std::make_unique<Task>(Task::Mode::SEQUENTIAL)} { compile_graph(graph); } -MPtr<CompiledGraph> -CompiledGraph::compile(Raul::Maid& maid, GraphImpl& graph) +std::unique_ptr<CompiledGraph> +CompiledGraph::compile(GraphImpl& graph) { try { - return maid.make_managed<CompiledGraph>(&graph); + return std::unique_ptr<CompiledGraph>(new CompiledGraph(&graph)); } catch (const FeedbackException& e) { Log& log = graph.engine().log(); if (e.node && e.root) { @@ -79,31 +87,29 @@ CompiledGraph::compile(Raul::Maid& maid, GraphImpl& graph) } else { log.error("Feedback compiling %1%\n", e.node->path()); } - return MPtr<CompiledGraph>(); + return nullptr; } } static size_t -num_unvisited_dependants(BlockImpl* block) +num_unvisited_dependants(const BlockImpl* block) { - size_t count = 0; - for (BlockImpl* b : block->dependants()) { - if (b->get_mark() == BlockImpl::Mark::UNVISITED) { - ++count; - } - } - return count; + return std::count_if(block->dependants().begin(), + block->dependants().end(), + [](const auto* b) { + return b->get_mark() == BlockImpl::Mark::UNVISITED; + }); } static size_t -parallel_depth(BlockImpl* block) +parallel_depth(const BlockImpl* block) { if (has_provider_with_many_dependants(block)) { return 2; } size_t min_provider_depth = std::numeric_limits<size_t>::max(); - for (auto p : block->providers()) { + for (const auto* p : block->providers()) { min_provider_depth = std::min(min_provider_depth, parallel_depth(p)); } @@ -133,12 +139,12 @@ CompiledGraph::compile_graph(GraphImpl* graph) // Calculate maximum sequential depth to consume this phase size_t depth = std::numeric_limits<size_t>::max(); - for (auto i : blocks) { + for (const auto* i : blocks) { depth = std::min(depth, parallel_depth(i)); } Task par(Task::Mode::PARALLEL); - for (auto b : blocks) { + for (auto* b : blocks) { assert(num_unvisited_dependants(b) == 0); Task seq(Task::Mode::SEQUENTIAL); compile_block(b, seq, depth, predecessors); @@ -151,7 +157,7 @@ CompiledGraph::compile_graph(GraphImpl* graph) _master = Task::simplify(std::move(_master)); if (graph->engine().world().conf().option("trace").get<int32_t>()) { - ColorContext ctx(stderr, ColorContext::Color::YELLOW); + const ColorContext ctx{stderr, ColorContext::Color::YELLOW}; dump(graph->path()); } } @@ -164,7 +170,7 @@ check_feedback(const BlockImpl* root, BlockImpl* provider) throw FeedbackException(root); } - for (auto p : provider->providers()) { + for (auto* p : provider->providers()) { const BlockImpl::Mark mark = p->get_mark(); switch (mark) { case BlockImpl::Mark::UNVISITED: @@ -227,12 +233,12 @@ CompiledGraph::compile_block(BlockImpl* n, if (n->providers().size() < 2) { // Single provider, prepend it to this sequential task - for (auto p : n->providers()) { + for (auto* p : n->providers()) { compile_provider(n, p, task, max_depth - 1, k); } } else if (has_provider_with_many_dependants(n)) { // Stop recursion and enqueue providers for the next round - for (auto p : n->providers()) { + for (auto* p : n->providers()) { if (num_unvisited_dependants(p) == 0) { k.insert(p); } @@ -241,7 +247,7 @@ CompiledGraph::compile_block(BlockImpl* n, // Multiple providers with only this node as dependant, // make a new parallel task to execute them Task par(Task::Mode::PARALLEL); - for (auto p : n->providers()) { + for (auto* p : n->providers()) { compile_provider(n, p, par, max_depth - 1, k); } task.push_front(std::move(par)); @@ -258,9 +264,9 @@ CompiledGraph::compile_block(BlockImpl* n, } void -CompiledGraph::run(RunContext& context) +CompiledGraph::run(RunContext& ctx) { - _master->run(context); + _master->run(ctx); } void @@ -276,5 +282,4 @@ CompiledGraph::dump(const std::string& name) const sink(")\n"); } -} // namespace server -} // namespace ingen +} // namespace ingen::server |