diff options
author | David Robillard <d@drobilla.net> | 2018-01-17 00:10:50 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-01-17 00:10:50 +0100 |
commit | bd50ebb65df099d84fcf8978c7dc1db7db3b2917 (patch) | |
tree | d9d842e08c82dcb92ca4b4494b52953735cbb851 | |
parent | 3441b4268a070418b6d7b7266d93b265ba79f45f (diff) | |
download | ingen-bd50ebb65df099d84fcf8978c7dc1db7db3b2917.tar.gz ingen-bd50ebb65df099d84fcf8978c7dc1db7db3b2917.tar.bz2 ingen-bd50ebb65df099d84fcf8978c7dc1db7db3b2917.zip |
Clean up Engine component memory management and trim include tree
-rw-r--r-- | src/server/BlockImpl.hpp | 2 | ||||
-rw-r--r-- | src/server/ClientUpdate.cpp | 8 | ||||
-rw-r--r-- | src/server/ClientUpdate.hpp | 2 | ||||
-rw-r--r-- | src/server/Engine.cpp | 63 | ||||
-rw-r--r-- | src/server/Engine.hpp | 93 | ||||
-rw-r--r-- | src/server/LV2Block.cpp | 2 | ||||
-rw-r--r-- | src/server/LV2Block.hpp | 2 | ||||
-rw-r--r-- | src/server/Worker.cpp | 6 | ||||
-rw-r--r-- | src/server/events/CreateBlock.cpp | 2 | ||||
-rw-r--r-- | src/server/events/CreateGraph.cpp | 2 | ||||
-rw-r--r-- | src/server/events/Delta.cpp | 4 | ||||
-rw-r--r-- | src/server/events/Get.cpp | 2 | ||||
-rw-r--r-- | src/server/events/Mark.cpp | 6 | ||||
-rw-r--r-- | src/server/events/Undo.cpp | 4 | ||||
-rw-r--r-- | src/server/ingen_engine.cpp | 3 | ||||
-rw-r--r-- | src/server/ingen_lv2.cpp | 24 |
16 files changed, 105 insertions, 120 deletions
diff --git a/src/server/BlockImpl.hpp b/src/server/BlockImpl.hpp index 62d6b8e0..7907b0d8 100644 --- a/src/server/BlockImpl.hpp +++ b/src/server/BlockImpl.hpp @@ -105,7 +105,7 @@ public: virtual LilvState* load_preset(const Raul::URI& uri) { return nullptr; } /** Restore `state`. */ - virtual void apply_state(Worker* worker, const LilvState* state) {} + virtual void apply_state(const UPtr<Worker>& worker, const LilvState* state) {} /** Save current state as preset. */ virtual boost::optional<Resource> diff --git a/src/server/ClientUpdate.cpp b/src/server/ClientUpdate.cpp index e4d9c08f..a5f85cef 100644 --- a/src/server/ClientUpdate.cpp +++ b/src/server/ClientUpdate.cpp @@ -132,22 +132,22 @@ put_higher_than(const ClientUpdate::Put& a, const ClientUpdate::Put& b) } void -ClientUpdate::send(Interface* dest) +ClientUpdate::send(Interface& dest) { // Send deletions for (const Raul::URI& subject : dels) { - dest->del(subject); + dest.del(subject); } // Send puts in increasing depth order so parents are sent first std::stable_sort(puts.begin(), puts.end(), put_higher_than); for (const ClientUpdate::Put& put : puts) { - dest->put(put.uri, put.properties, put.ctx); + dest.put(put.uri, put.properties, put.ctx); } // Send connections for (const ClientUpdate::Connect& connect : connects) { - dest->connect(connect.tail, connect.head); + dest.connect(connect.tail, connect.head); } } diff --git a/src/server/ClientUpdate.hpp b/src/server/ClientUpdate.hpp index ea11c2b8..008bf2da 100644 --- a/src/server/ClientUpdate.hpp +++ b/src/server/ClientUpdate.hpp @@ -57,7 +57,7 @@ struct ClientUpdate { void del(const Raul::URI& subject); - void send(Interface* dest); + void send(Interface& dest); struct Put { Raul::URI uri; diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index 628d0b50..e8d4770e 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -66,23 +66,23 @@ bool ThreadManager::single_threaded(true); Engine::Engine(Ingen::World* world) : _world(world) + , _options(new LV2Options(world->uris())) + , _buffer_factory(new BufferFactory(*this, world->uris())) , _maid(new Raul::Maid) - , _block_factory(new BlockFactory(world)) + , _worker(new Worker(world->log(), event_queue_size())) + , _sync_worker(new Worker(world->log(), event_queue_size(), true)) , _broadcaster(new Broadcaster()) - , _buffer_factory(new BufferFactory(*this, world->uris())) - , _control_bindings(nullptr) - , _event_writer(new EventWriter(*this)) - , _interface(_event_writer) - , _atom_interface(nullptr) - , _options(new LV2Options(world->uris())) + , _control_bindings(new ControlBindings(*this)) + , _block_factory(new BlockFactory(world)) , _undo_stack(new UndoStack(_world->uris(), _world->uri_map())) , _redo_stack(new UndoStack(_world->uris(), _world->uri_map())) - , _pre_processor(new PreProcessor(*this)) , _post_processor(new PostProcessor(*this)) + , _pre_processor(new PreProcessor(*this)) + , _event_writer(new EventWriter(*this)) + , _interface(_event_writer) + , _atom_interface( + new AtomReader(world->uri_map(), world->uris(), world->log(), *_interface)) , _root_graph(nullptr) - , _worker(new Worker(world->log(), event_queue_size())) - , _sync_worker(new Worker(world->log(), event_queue_size(), true)) - , _listener(nullptr) , _cycle_start_time(0) , _rand_engine(0) , _uniform_dist(0.0f, 1.0f) @@ -95,8 +95,6 @@ Engine::Engine(Ingen::World* world) world->set_store(SPtr<Ingen::Store>(new Store())); } - _control_bindings = new ControlBindings(*this); - for (int i = 0; i < world->conf().option("threads").get<int32_t>(); ++i) { Raul::RingBuffer* ring = new Raul::RingBuffer(24 * event_queue_size()); _notifications.push_back(ring); @@ -128,9 +126,6 @@ Engine::Engine(Ingen::World* world) stderr, ColorContext::Color::MAGENTA)}); } - - _atom_interface = new AtomReader( - world->uri_map(), world->uris(), world->log(), *_interface.get()); } Engine::~Engine() @@ -149,7 +144,7 @@ Engine::~Engine() _post_processor->process(); } - delete _atom_interface; + _atom_interface.reset(); // Delete run contexts _quit_flag = true; @@ -173,33 +168,13 @@ Engine::~Engine() } _world->set_store(SPtr<Ingen::Store>()); - -#ifdef HAVE_SOCKET - delete _listener; -#endif - delete _pre_processor; - delete _post_processor; - delete _undo_stack; - delete _redo_stack; - delete _block_factory; - delete _control_bindings; - delete _broadcaster; - delete _sync_worker; - delete _worker; - delete _maid; - - _driver.reset(); - - delete _buffer_factory; - - munlockall(); } void Engine::listen() { #ifdef HAVE_SOCKET - _listener = new SocketListener(*this); + _listener = UPtr<SocketListener>(new SocketListener(*this)); #endif } @@ -220,6 +195,12 @@ Engine::locate(FrameTime s, SampleCount nframes) } void +Engine::set_root_graph(GraphImpl* graph) +{ + _root_graph = graph; +} + +void Engine::flush_events(const std::chrono::milliseconds& sleep_ms) { bool finished = !pending_events(); @@ -521,6 +502,12 @@ Engine::process_all_events() return _pre_processor->process(run_context(), *_post_processor, 0); } +Log& +Engine::log() const +{ + return _world->log(); +} + void Engine::register_client(SPtr<Interface> client) { diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp index 4832e81d..f5ba1feb 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -24,23 +24,22 @@ #include "ingen/Clock.hpp" #include "ingen/EngineBase.hpp" -#include "ingen/Interface.hpp" #include "ingen/Properties.hpp" -#include "ingen/World.hpp" #include "ingen/ingen.h" #include "ingen/types.hpp" -#include "raul/Noncopyable.hpp" #include "Event.hpp" -#include "EventWriter.hpp" #include "Load.hpp" -#include "RunContext.hpp" -namespace Raul { class Maid; } +namespace Raul { +class Maid; +class RingBuffer; +} namespace Ingen { class AtomReader; +class Interface; class Log; class Store; class World; @@ -52,12 +51,14 @@ class Broadcaster; class BufferFactory; class ControlBindings; class Driver; +class EventWriter; class GraphImpl; class LV2Options; class PostProcessor; class PreProcessor; class RunContext; class SocketListener; +class Task; class UndoStack; class Worker; @@ -70,13 +71,15 @@ class Worker; @ingroup engine */ -class INGEN_API Engine : public Raul::Noncopyable, public EngineBase +class INGEN_API Engine : public EngineBase { public: explicit Engine(Ingen::World* world); - virtual ~Engine(); + Engine(const Engine&) = delete; + Engine& operator=(const Engine&) = delete; + // EngineBase methods virtual void init(double sample_rate, uint32_t block_length, size_t seq_size); virtual bool supports_dynamic_ports() const; @@ -127,28 +130,28 @@ public: unsigned process_all_events(); Ingen::World* world() const { return _world; } - - Interface* interface() const { return _interface.get(); } - EventWriter* event_writer() const { return _event_writer.get(); } - AtomReader* atom_interface() const { return _atom_interface; } - BlockFactory* block_factory() const { return _block_factory; } - Broadcaster* broadcaster() const { return _broadcaster; } - BufferFactory* buffer_factory() const { return _buffer_factory; } - ControlBindings* control_bindings() const { return _control_bindings; } - Driver* driver() const { return _driver.get(); } - Log& log() const { return _world->log(); } - GraphImpl* root_graph() const { return _root_graph; } - PostProcessor* post_processor() const { return _post_processor; } - Raul::Maid* maid() const { return _maid; } - UndoStack* undo_stack() const { return _undo_stack; } - UndoStack* redo_stack() const { return _redo_stack; } - Worker* worker() const { return _worker; } - Worker* sync_worker() const { return _sync_worker; } + Log& log() const; + + const SPtr<Interface>& interface() const { return _interface; } + const SPtr<EventWriter>& event_writer() const { return _event_writer; } + const UPtr<AtomReader>& atom_interface() const { return _atom_interface; } + const UPtr<BlockFactory>& block_factory() const { return _block_factory; } + const UPtr<Broadcaster>& broadcaster() const { return _broadcaster; } + const UPtr<BufferFactory>& buffer_factory() const { return _buffer_factory; } + const UPtr<ControlBindings>& control_bindings() const { return _control_bindings; } + const SPtr<Driver>& driver() const { return _driver; } + const UPtr<PostProcessor>& post_processor() const { return _post_processor; } + const UPtr<Raul::Maid>& maid() const { return _maid; } + const UPtr<UndoStack>& undo_stack() const { return _undo_stack; } + const UPtr<UndoStack>& redo_stack() const { return _redo_stack; } + const UPtr<Worker>& worker() const { return _worker; } + const UPtr<Worker>& sync_worker() const { return _sync_worker; } + + GraphImpl* root_graph() const { return _root_graph; } + void set_root_graph(GraphImpl* graph); RunContext& run_context() { return *_run_contexts[0]; } - void set_root_graph(GraphImpl* graph) { _root_graph = graph; } - void flush_events(const std::chrono::milliseconds& sleep_ms); void advance(SampleCount nframes); @@ -175,24 +178,24 @@ public: private: Ingen::World* _world; - Raul::Maid* _maid; - BlockFactory* _block_factory; - Broadcaster* _broadcaster; - BufferFactory* _buffer_factory; - ControlBindings* _control_bindings; - SPtr<Driver> _driver; - SPtr<EventWriter> _event_writer; - SPtr<Interface> _interface; - AtomReader* _atom_interface; - SPtr<LV2Options> _options; - UndoStack* _undo_stack; - UndoStack* _redo_stack; - PreProcessor* _pre_processor; - PostProcessor* _post_processor; - GraphImpl* _root_graph; - Worker* _worker; - Worker* _sync_worker; - SocketListener* _listener; + SPtr<LV2Options> _options; + UPtr<BufferFactory> _buffer_factory; + UPtr<Raul::Maid> _maid; + SPtr<Driver> _driver; + UPtr<Worker> _worker; + UPtr<Worker> _sync_worker; + UPtr<Broadcaster> _broadcaster; + UPtr<ControlBindings> _control_bindings; + UPtr<BlockFactory> _block_factory; + UPtr<UndoStack> _undo_stack; + UPtr<UndoStack> _redo_stack; + UPtr<PostProcessor> _post_processor; + UPtr<PreProcessor> _pre_processor; + UPtr<SocketListener> _listener; + SPtr<EventWriter> _event_writer; + SPtr<Interface> _interface; + UPtr<AtomReader> _atom_interface; + GraphImpl* _root_graph; std::vector<Raul::RingBuffer*> _notifications; std::vector<RunContext*> _run_contexts; diff --git a/src/server/LV2Block.cpp b/src/server/LV2Block.cpp index 8b719b49..440fb3c5 100644 --- a/src/server/LV2Block.cpp +++ b/src/server/LV2Block.cpp @@ -641,7 +641,7 @@ LV2Block::load_state(World* world, const std::string& path) } void -LV2Block::apply_state(Worker* worker, const LilvState* state) +LV2Block::apply_state(const UPtr<Worker>& worker, const LilvState* state) { World* world = parent_graph()->engine().world(); SPtr<LV2_Feature> sched; diff --git a/src/server/LV2Block.hpp b/src/server/LV2Block.hpp index cce0626a..d04d2048 100644 --- a/src/server/LV2Block.hpp +++ b/src/server/LV2Block.hpp @@ -70,7 +70,7 @@ public: LilvState* load_preset(const Raul::URI& uri); - void apply_state(Worker* worker, const LilvState* state); + void apply_state(const UPtr<Worker>& worker, const LilvState* state); boost::optional<Resource> save_preset(const Raul::URI& uri, const Properties& props); diff --git a/src/server/Worker.cpp b/src/server/Worker.cpp index 51b37797..6f60250c 100644 --- a/src/server/Worker.cpp +++ b/src/server/Worker.cpp @@ -40,9 +40,8 @@ schedule(LV2_Worker_Schedule_Handle handle, { LV2Block* block = (LV2Block*)handle; Engine& engine = block->parent_graph()->engine(); - Worker* worker = engine.worker(); - return worker->request(block, size, data); + return engine.worker()->request(block, size, data); } static LV2_Worker_Status @@ -52,9 +51,8 @@ schedule_sync(LV2_Worker_Schedule_Handle handle, { LV2Block* block = (LV2Block*)handle; Engine& engine = block->parent_graph()->engine(); - Worker* worker = engine.sync_worker(); - return worker->request(block, size, data); + return engine.sync_worker()->request(block, size, data); } LV2_Worker_Status diff --git a/src/server/events/CreateBlock.cpp b/src/server/events/CreateBlock.cpp index 1a70223c..eb307711 100644 --- a/src/server/events/CreateBlock.cpp +++ b/src/server/events/CreateBlock.cpp @@ -164,7 +164,7 @@ CreateBlock::post_process() { Broadcaster::Transfer t(*_engine.broadcaster()); if (respond() == Status::SUCCESS) { - _update.send(_engine.broadcaster()); + _update.send(*_engine.broadcaster()); } } diff --git a/src/server/events/CreateGraph.cpp b/src/server/events/CreateGraph.cpp index 7a2c7304..43b3bb97 100644 --- a/src/server/events/CreateGraph.cpp +++ b/src/server/events/CreateGraph.cpp @@ -215,7 +215,7 @@ CreateGraph::post_process() { Broadcaster::Transfer t(*_engine.broadcaster()); if (respond() == Status::SUCCESS) { - _update.send(_engine.broadcaster()); + _update.send(*_engine.broadcaster()); } if (_graph) { diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index e120e610..b7cb9475 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -602,7 +602,7 @@ Delta::post_process() } if (respond() == Status::SUCCESS) { - _update.send(_engine.broadcaster()); + _update.send(*_engine.broadcaster()); switch (_type) { case Type::SET: @@ -625,7 +625,7 @@ Delta::post_process() // Preset save ClientUpdate response; response.put(_preset->uri(), _preset->properties()); - response.send(_engine.broadcaster()); + response.send(*_engine.broadcaster()); } else { // Graph object put _engine.broadcaster()->put(_subject, _properties, _context); diff --git a/src/server/events/Get.cpp b/src/server/events/Get.cpp index e4a5c760..84f6f251 100644 --- a/src/server/events/Get.cpp +++ b/src/server/events/Get.cpp @@ -101,7 +101,7 @@ Get::post_process() props.insert(load_props.begin(), load_props.end()); _request_client->put(Raul::URI("ingen:/engine"), props); } else { - _response.send(_request_client.get()); + _response.send(*_request_client); } } } diff --git a/src/server/events/Mark.cpp b/src/server/events/Mark.cpp index eb956f17..90b449d5 100644 --- a/src/server/events/Mark.cpp +++ b/src/server/events/Mark.cpp @@ -44,9 +44,9 @@ Mark::Mark(Engine& engine, bool Mark::pre_process(PreProcessContext& ctx) { - UndoStack* const stack = ((_mode == Mode::UNDO) - ? _engine.redo_stack() - : _engine.undo_stack()); + const UPtr<UndoStack>& stack = ((_mode == Mode::UNDO) + ? _engine.redo_stack() + : _engine.undo_stack()); switch (_type) { case Type::BUNDLE_BEGIN: diff --git a/src/server/events/Undo.cpp b/src/server/events/Undo.cpp index a6c80217..e06a5951 100644 --- a/src/server/events/Undo.cpp +++ b/src/server/events/Undo.cpp @@ -43,8 +43,8 @@ Undo::Undo(Engine& engine, bool Undo::pre_process(PreProcessContext& ctx) { - UndoStack* const stack = _is_redo ? _engine.redo_stack() : _engine.undo_stack(); - const Event::Mode mode = _is_redo ? Event::Mode::REDO : Event::Mode::UNDO; + const UPtr<UndoStack>& stack = _is_redo ? _engine.redo_stack() : _engine.undo_stack(); + const Event::Mode mode = _is_redo ? Event::Mode::REDO : Event::Mode::UNDO; if (stack->empty()) { return Event::pre_process_done(Status::NOT_FOUND); diff --git a/src/server/ingen_engine.cpp b/src/server/ingen_engine.cpp index 2805603a..3409f1bf 100644 --- a/src/server/ingen_engine.cpp +++ b/src/server/ingen_engine.cpp @@ -28,8 +28,7 @@ struct IngenEngineModule : public Ingen::Module { SPtr<Server::Engine> engine(new Server::Engine(world)); world->set_engine(engine); if (!world->interface()) { - world->set_interface( - SPtr<Interface>(engine->interface(), NullDeleter<Interface>)); + world->set_interface(engine->interface()); } } }; diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index 8dfea405..1b6652ae 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -405,7 +405,7 @@ using namespace Ingen; using namespace Ingen::Server; static void -ingen_lv2_main(SPtr<Engine> engine, LV2Driver* driver) +ingen_lv2_main(SPtr<Engine> engine, const SPtr<LV2Driver>& driver) { while (true) { // Wait until there is work to be done @@ -551,8 +551,7 @@ ingen_instantiate(const LV2_Descriptor* descriptor, plugin->engine = engine; plugin->world->set_engine(engine); - SPtr<Interface> interface = SPtr<Interface>(engine->interface(), - NullDeleter<Interface>); + SPtr<Interface> interface = engine->interface(); plugin->world->set_interface(interface); @@ -600,9 +599,9 @@ ingen_connect_port(LV2_Handle instance, uint32_t port, void* data) { using namespace Ingen::Server; - IngenPlugin* me = (IngenPlugin*)instance; - Server::Engine* engine = (Server::Engine*)me->world->engine().get(); - LV2Driver* driver = (LV2Driver*)engine->driver(); + IngenPlugin* me = (IngenPlugin*)instance; + Server::Engine* engine = (Server::Engine*)me->world->engine().get(); + const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); if (port < driver->ports().size()) { driver->ports().at(port)->set_buffer(data); } else { @@ -613,10 +612,9 @@ ingen_connect_port(LV2_Handle instance, uint32_t port, void* data) static void ingen_activate(LV2_Handle instance) { - IngenPlugin* me = (IngenPlugin*)instance; - SPtr<Server::Engine> engine = dynamic_ptr_cast<Server::Engine>( - me->world->engine()); - LV2Driver* driver = (LV2Driver*)engine->driver(); + IngenPlugin* me = (IngenPlugin*)instance; + SPtr<Server::Engine> engine = static_ptr_cast<Server::Engine>(me->world->engine()); + const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); engine->activate(); me->main = new std::thread(ingen_lv2_main, engine, driver); } @@ -624,9 +622,9 @@ ingen_activate(LV2_Handle instance) static void ingen_run(LV2_Handle instance, uint32_t sample_count) { - IngenPlugin* me = (IngenPlugin*)instance; - Server::Engine* engine = (Server::Engine*)me->world->engine().get(); - LV2Driver* driver = (LV2Driver*)engine->driver(); + IngenPlugin* me = (IngenPlugin*)instance; + SPtr<Server::Engine> engine = static_ptr_cast<Server::Engine>(me->world->engine()); + const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); Server::ThreadManager::set_flag(Ingen::Server::THREAD_PROCESS); Server::ThreadManager::set_flag(Ingen::Server::THREAD_IS_REAL_TIME); |