From b5e0b5b09f41d2529bf4ba37f69602f914828e58 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 28 Jul 2017 20:15:15 +0200 Subject: [PATCH] PortManager::unregister_port() must be called with process lock This fixes "Failed to register port" when re-loading a session. --- libs/ardour/midiport_manager.cc | 1 + libs/surfaces/faderport/faderport.cc | 2 ++ libs/surfaces/faderport8/faderport8.cc | 2 ++ libs/surfaces/mackie/surface_port.cc | 2 ++ libs/surfaces/push2/push2.cc | 7 +++++-- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libs/ardour/midiport_manager.cc b/libs/ardour/midiport_manager.cc index 7f5dee4c64..cf1d90ac56 100644 --- a/libs/ardour/midiport_manager.cc +++ b/libs/ardour/midiport_manager.cc @@ -37,6 +37,7 @@ MidiPortManager::MidiPortManager () MidiPortManager::~MidiPortManager () { + Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock()); if (_midi_in) { AudioEngine::instance()->unregister_port (_midi_in); } diff --git a/libs/surfaces/faderport/faderport.cc b/libs/surfaces/faderport/faderport.cc index 4e65fec3cc..4984c73b06 100644 --- a/libs/surfaces/faderport/faderport.cc +++ b/libs/surfaces/faderport/faderport.cc @@ -200,6 +200,7 @@ FaderPort::~FaderPort () if (_input_port) { DEBUG_TRACE (DEBUG::FaderPort, string_compose ("unregistering input port %1\n", boost::shared_ptr(_input_port)->name())); + Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock()); AudioEngine::instance()->unregister_port (_input_port); _input_port.reset (); } @@ -207,6 +208,7 @@ FaderPort::~FaderPort () if (_output_port) { _output_port->drain (10000, 250000); /* check every 10 msecs, wait up to 1/4 second for the port to drain */ DEBUG_TRACE (DEBUG::FaderPort, string_compose ("unregistering output port %1\n", boost::shared_ptr(_output_port)->name())); + Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock()); AudioEngine::instance()->unregister_port (_output_port); _output_port.reset (); } diff --git a/libs/surfaces/faderport8/faderport8.cc b/libs/surfaces/faderport8/faderport8.cc index a812e1a4d7..9b35578255 100644 --- a/libs/surfaces/faderport8/faderport8.cc +++ b/libs/surfaces/faderport8/faderport8.cc @@ -155,6 +155,7 @@ FaderPort8::~FaderPort8 () if (_input_port) { DEBUG_TRACE (DEBUG::FaderPort8, string_compose ("unregistering input port %1\n", boost::shared_ptr(_input_port)->name())); + Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock()); AudioEngine::instance()->unregister_port (_input_port); _input_port.reset (); } @@ -164,6 +165,7 @@ FaderPort8::~FaderPort8 () if (_output_port) { _output_port->drain (10000, 250000); /* check every 10 msecs, wait up to 1/4 second for the port to drain */ DEBUG_TRACE (DEBUG::FaderPort8, string_compose ("unregistering output port %1\n", boost::shared_ptr(_output_port)->name())); + Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock()); AudioEngine::instance()->unregister_port (_output_port); _output_port.reset (); } diff --git a/libs/surfaces/mackie/surface_port.cc b/libs/surfaces/mackie/surface_port.cc index 4ecb565735..b6bc26cc77 100644 --- a/libs/surfaces/mackie/surface_port.cc +++ b/libs/surfaces/mackie/surface_port.cc @@ -92,6 +92,7 @@ SurfacePort::~SurfacePort() } else { if (_async_in) { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("unregistering input port %1\n", _async_in->name())); + Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock()); AudioEngine::instance()->unregister_port (_async_in); _async_in.reset ((ARDOUR::Port*) 0); } @@ -99,6 +100,7 @@ SurfacePort::~SurfacePort() if (_async_out) { _output_port->drain (10000, 250000); DEBUG_TRACE (DEBUG::MackieControl, string_compose ("unregistering output port %1\n", _async_out->name())); + Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock()); AudioEngine::instance()->unregister_port (_async_out); _async_out.reset ((ARDOUR::Port*) 0); } diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index f29ff41d06..d884869048 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -294,8 +294,11 @@ Push2::ports_release () asp = dynamic_cast (_output_port); asp->drain (10000, 500000); - AudioEngine::instance()->unregister_port (_async_in); - AudioEngine::instance()->unregister_port (_async_out); + { + Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock()); + AudioEngine::instance()->unregister_port (_async_in); + AudioEngine::instance()->unregister_port (_async_out); + } _async_in.reset ((ARDOUR::Port*) 0); _async_out.reset ((ARDOUR::Port*) 0);