summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-05-03 08:07:59 +0000
committerDavid Robillard <d@drobilla.net>2012-05-03 08:07:59 +0000
commit628e2f1606aead224c317d17b3e038122db61110 (patch)
treed1345665fbf3e36404ebe1bad3ba395bfe8e2fd1
parent02dcc06a1675e936ef85714827accb20a9f2a94c (diff)
downloadingen-628e2f1606aead224c317d17b3e038122db61110.tar.gz
ingen-628e2f1606aead224c317d17b3e038122db61110.tar.bz2
ingen-628e2f1606aead224c317d17b3e038122db61110.zip
Real-time safe event source management (oops).
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4321 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/server/Engine.cpp23
-rw-r--r--src/server/Engine.hpp7
-rw-r--r--src/server/EventSource.hpp10
3 files changed, 26 insertions, 14 deletions
diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp
index 77630d54..7138d2ea 100644
--- a/src/server/Engine.cpp
+++ b/src/server/Engine.cpp
@@ -125,7 +125,10 @@ Engine::main_iteration()
void
Engine::add_event_source(SharedPtr<EventSource> source)
{
- _event_sources.insert(source);
+ // FIXME: Not thread-safe
+ _maid->manage(source);
+ source->_next = _event_sources;
+ _event_sources = source;
}
void
@@ -237,14 +240,18 @@ Engine::process_events(ProcessContext& context)
{
ThreadManager::assert_thread(THREAD_PROCESS);
- EventSources::iterator i = _event_sources.begin();
- while (i != _event_sources.end()) {
- EventSources::iterator next = i;
- ++next;
- if (!(*i)->process(*_post_processor, context)) {
- _event_sources.erase(i);
+ SharedPtr<EventSource> src = _event_sources;
+ SharedPtr<EventSource> prev = src;
+ for (; src; src = src->_next) {
+ if (!src->process(*_post_processor, context)) {
+ // Source is finished, remove
+ if (src == _event_sources) {
+ _event_sources = src->_next;
+ } else {
+ prev->_next = src->_next;
+ }
}
- i = next;
+ prev = src;
}
}
diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp
index 8e5f381f..5f218078 100644
--- a/src/server/Engine.hpp
+++ b/src/server/Engine.hpp
@@ -17,15 +17,13 @@
#ifndef INGEN_ENGINE_ENGINE_HPP
#define INGEN_ENGINE_ENGINE_HPP
-#include <set>
#include <vector>
#include <boost/utility.hpp>
-#include "raul/SharedPtr.hpp"
-
#include "ingen/EngineBase.hpp"
#include "ingen/Interface.hpp"
+#include "raul/SharedPtr.hpp"
namespace Raul { class Maid; }
@@ -101,8 +99,7 @@ private:
NodeFactory* _node_factory;
PostProcessor* _post_processor;
- typedef std::set< SharedPtr<EventSource> > EventSources;
- EventSources _event_sources;
+ SharedPtr<EventSource> _event_sources; ///< Intrusive linked list
bool _quit_flag;
};
diff --git a/src/server/EventSource.hpp b/src/server/EventSource.hpp
index 65afece4..320b6b7a 100644
--- a/src/server/EventSource.hpp
+++ b/src/server/EventSource.hpp
@@ -17,6 +17,9 @@
#ifndef INGEN_ENGINE_EVENTSOURCE_HPP
#define INGEN_ENGINE_EVENTSOURCE_HPP
+#include <raul/SharedPtr.hpp>
+#include <raul/Deletable.hpp>
+
namespace Ingen {
namespace Server {
@@ -30,9 +33,10 @@ class ProcessContext;
* executes them, then they are sent to the PostProcessor and finalised
* (post-processing thread).
*/
-class EventSource
+class EventSource : public Raul::Deletable
{
public:
+ EventSource() {}
virtual ~EventSource() {}
/** Process events for a cycle.
@@ -41,6 +45,10 @@ public:
virtual bool process(PostProcessor& dest,
ProcessContext& context,
bool limit = true) = 0;
+
+private:
+ friend class Engine;
+ SharedPtr<EventSource> _next; ///< Intrusive linked list for Engine
};
} // namespace Server