From f8cd75372d9c45a0a8616d89a18a5b9906ac9d54 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 12 Nov 2017 19:57:56 +0100 Subject: WIP: Clean up task implementation --- src/server/Work.hpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/server/Work.hpp (limited to 'src/server/Work.hpp') diff --git a/src/server/Work.hpp b/src/server/Work.hpp new file mode 100644 index 00000000..bfbc9ed0 --- /dev/null +++ b/src/server/Work.hpp @@ -0,0 +1,55 @@ +/* + This file is part of Ingen. + Copyright 2007-2017 David Robillard + + 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 + Software Foundation, either version 3 of the License, or any later version. + + Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see . +*/ + +#ifndef INGEN_ENGINE_WORK_HPP +#define INGEN_ENGINE_WORK_HPP + +#include + +namespace Ingen { +namespace Server { + +template +class Work { +public: + enum class Mode { + UNIT, ///< Single unit to run + SEQUENTIAL, ///< Elements must be run sequentially in order + PARALLEL ///< Elements may be run in any order in parallel + }; + + static Work unit(Unit& unit) { return Work(Mode::UNIT, &unit); } + static Work sequential() { return Work(Mode::SEQUENTIAL); } + static Work parallel() { return Work(Mode::PARALLEL); } + + void prepend(Work&& work) { _children.emplace_back(std::move(work)); } + + Unit* unit() const { return _unit; } + Mode mode() const { return _mode; } + const std::vector& children() const { return _children; } + +private: + Work(Mode mode, Unit* unit = nullptr) : _unit(unit), _mode(mode) {} + + std::vector _children; ///< Children in reverse execution order + Unit* const _unit; ///< Used for UNIT mode only + const Mode _mode; ///< Execution mode +}; + +} // namespace Server +} // namespace Ingen + +#endif // INGEN_ENGINE_WORK_HPP -- cgit v1.2.1