summaryrefslogtreecommitdiffstats
path: root/src/server/PreProcessContext.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-10-01 15:18:09 -0400
committerDavid Robillard <d@drobilla.net>2016-10-02 12:24:57 -0400
commita172e76897157e5a0d2ebd3fa3f7f77ec38a5df0 (patch)
treeafc1962fc5123ff8ad4558912e69227bca2a4192 /src/server/PreProcessContext.hpp
parent5c4356827e51b3d6e1256a050e6273a87728d588 (diff)
downloadingen-a172e76897157e5a0d2ebd3fa3f7f77ec38a5df0.tar.gz
ingen-a172e76897157e5a0d2ebd3fa3f7f77ec38a5df0.tar.bz2
ingen-a172e76897157e5a0d2ebd3fa3f7f77ec38a5df0.zip
Defer graph compilation in atomic bundles
This avoids situations like compiling a graph hundreds of times when it is loaded because it has hundreds of nodes and each event triggers a re-compile. This speeds things up dramatically, but exacerbates the theoretical problem of there not being enough time in a cycle to execute a bundle. As far as I can tell, the execute phase of events is very fast, so hundreds or thousands can easily run in a tiny fraction of the process cycle, but this still needs resolution to be truly hard real-time. What probably needs to happen is that all context and state used to process is moved to CompiledGraph and nodes do not access their own fields at all, but have some references into the CompiledGraph. This way, a compiled graph is separate from its "source code", and an old one could continue to be run while a new one is beng applied across several cycles.
Diffstat (limited to 'src/server/PreProcessContext.hpp')
-rw-r--r--src/server/PreProcessContext.hpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/server/PreProcessContext.hpp b/src/server/PreProcessContext.hpp
new file mode 100644
index 00000000..bf1115e8
--- /dev/null
+++ b/src/server/PreProcessContext.hpp
@@ -0,0 +1,70 @@
+/*
+ This file is part of Ingen.
+ Copyright 2007-2016 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_PREPROCESSCONTEXT_HPP
+#define INGEN_ENGINE_PREPROCESSCONTEXT_HPP
+
+#include <unordered_set>
+
+#include "GraphImpl.hpp"
+
+namespace Ingen {
+namespace Server {
+
+/** Event pre-processing context.
+ *
+ * \ingroup engine
+ */
+class PreProcessContext
+{
+public:
+ typedef std::unordered_set<GraphImpl*> DirtyGraphs;
+
+ /** Return true iff an atomic bundle is currently being pre-processed. */
+ bool in_bundle() const { return _in_bundle; }
+
+ /** Set/unset atomic bundle flag. */
+ void set_in_bundle(bool b) { _in_bundle = b; }
+
+ /** Return true iff graph should be compiled now (after a change).
+ *
+ * This may return false when an atomic bundle is deferring compilation, in
+ * which case the graph is flagged as dirty for later compilation.
+ */
+ bool must_compile(GraphImpl* graph) {
+ if (!graph->enabled()) {
+ return false;
+ } else if (_in_bundle) {
+ _dirty_graphs.insert(graph);
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /** Return all graphs that require compilation after an atomic bundle. */
+ const DirtyGraphs& dirty_graphs() const { return _dirty_graphs; }
+ DirtyGraphs& dirty_graphs() { return _dirty_graphs; }
+
+private:
+ DirtyGraphs _dirty_graphs;
+ bool _in_bundle = false;
+};
+
+} // namespace Server
+} // namespace Ingen
+
+#endif // INGEN_ENGINE_PREPROCESSCONTEXT_HPP