From eb10d32d8b59f2158ba64ba55e310ba0f5f24170 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 14 May 2008 23:31:15 +0000 Subject: Fix clear patch command (ticket #18). Potential destruction race/leak fixes. More thorough thread assertions on graph object methods. git-svn-id: http://svn.drobilla.net/lad/ingen@1207 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/PatchImpl.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/libs/engine/PatchImpl.cpp') diff --git a/src/libs/engine/PatchImpl.cpp b/src/libs/engine/PatchImpl.cpp index 13576f1c..dba3d747 100644 --- a/src/libs/engine/PatchImpl.cpp +++ b/src/libs/engine/PatchImpl.cpp @@ -85,6 +85,8 @@ PatchImpl::deactivate() void PatchImpl::disable() { + assert(ThreadManager::current_thread_id() == THREAD_PROCESS); + _process = false; for (List::iterator i = _output_ports.begin(); i != _output_ports.end(); ++i) @@ -95,6 +97,8 @@ PatchImpl::disable() bool PatchImpl::prepare_internal_poly(uint32_t poly) { + assert(ThreadManager::current_thread_id() == THREAD_PRE_PROCESS); + /* TODO: ports? internal/external poly? */ for (List::iterator i = _nodes.begin(); i != _nodes.end(); ++i) @@ -112,6 +116,8 @@ PatchImpl::prepare_internal_poly(uint32_t poly) bool PatchImpl::apply_internal_poly(Raul::Maid& maid, uint32_t poly) { + assert(ThreadManager::current_thread_id() == THREAD_PROCESS); + /* TODO: ports? internal/external poly? */ for (List::iterator i = _nodes.begin(); i != _nodes.end(); ++i) @@ -239,17 +245,23 @@ PatchImpl::set_buffer_size(size_t size) NodeBase::set_buffer_size(size); assert(_buffer_size == size); - for (List::iterator j = _nodes.begin(); j != _nodes.end(); ++j) - (*j)->set_buffer_size(size); + CompiledPatch* const cp = _compiled_patch; + + for (size_t i=0; i < cp->size(); ++i) + (*cp)[i].node()->set_buffer_size(size); } // Patch specific stuff +/** Add a node. + * Preprocessing thread only. + */ void PatchImpl::add_node(List::Node* ln) { + assert(ThreadManager::current_thread_id() == THREAD_PRE_PROCESS); assert(ln != NULL); assert(ln->elem() != NULL); assert(ln->elem()->parent_patch() == this); @@ -260,11 +272,12 @@ PatchImpl::add_node(List::Node* ln) /** Remove a node. - * Realtime Safe. Preprocessing thread. + * Preprocessing thread only. */ PatchImpl::Nodes::Node* PatchImpl::remove_node(const string& name) { + assert(ThreadManager::current_thread_id() == THREAD_PRE_PROCESS); for (List::iterator i = _nodes.begin(); i != _nodes.end(); ++i) if ((*i)->name() == name) return _nodes.erase(i); @@ -273,11 +286,13 @@ PatchImpl::remove_node(const string& name) } -/** Remove a connection. Realtime safe. +/** Remove a connection. + * Process thread only. */ PatchImpl::Connections::Node* PatchImpl::remove_connection(const PortImpl* src_port, const PortImpl* dst_port) { + assert(ThreadManager::current_thread_id() == THREAD_PROCESS); bool found = false; Connections::Node* connection = NULL; for (Connections::iterator i = _connections.begin(); i != _connections.end(); ++i) { @@ -360,6 +375,23 @@ PatchImpl::remove_port(const string& name) } +/** Remove all ports from ports list used in pre-processing thread. + * + * Ports are not removed from ports array for process thread (which could be + * simultaneously running). Returned is a (inputs, outputs) pair. + * + * Realtime safe. Preprocessing thread only. + */ +void +PatchImpl::clear_ports() +{ + assert(ThreadManager::current_thread_id() == THREAD_PROCESS); + + _input_ports.clear(); + _output_ports.clear(); +} + + Raul::Array* PatchImpl::build_ports_array() const { -- cgit v1.2.1