summaryrefslogtreecommitdiffstats
path: root/src/server/Work.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Work.hpp')
-rw-r--r--src/server/Work.hpp55
1 files changed, 55 insertions, 0 deletions
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 <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
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef INGEN_ENGINE_WORK_HPP
+#define INGEN_ENGINE_WORK_HPP
+
+#include <vector>
+
+namespace Ingen {
+namespace Server {
+
+template<typename Unit>
+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<Work>& children() const { return _children; }
+
+private:
+ Work(Mode mode, Unit* unit = nullptr) : _unit(unit), _mode(mode) {}
+
+ std::vector<Work> _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