From 628e2f1606aead224c317d17b3e038122db61110 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 3 May 2012 08:07:59 +0000 Subject: Real-time safe event source management (oops). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4321 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/Engine.cpp | 23 +++++++++++++++-------- src/server/Engine.hpp | 7 ++----- src/server/EventSource.hpp | 10 +++++++++- 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 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 src = _event_sources; + SharedPtr 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 #include #include -#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 > EventSources; - EventSources _event_sources; + SharedPtr _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 +#include + 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 _next; ///< Intrusive linked list for Engine }; } // namespace Server -- cgit v1.2.1