Disconnect Signals before dropping ports

significantly speeds up session close
This commit is contained in:
Robin Gareus 2016-04-24 00:24:43 +02:00
parent 2a7a64a873
commit f8936ebcb1
3 changed files with 23 additions and 4 deletions

View File

@ -125,6 +125,7 @@ public:
PBD::Signal1<void,bool> MonitorInputChanged;
static PBD::Signal2<void,boost::shared_ptr<Port>,boost::shared_ptr<Port> > PostDisconnect;
static PBD::Signal0<void> PortDrop;
static PBD::Signal0<void> PortSignalDrop;
static void set_cycle_framecnt (pframes_t n) {
_cycle_nframes = n;
@ -170,6 +171,7 @@ private:
std::set<std::string> _connections;
void port_connected_or_disconnected (boost::weak_ptr<Port>, boost::weak_ptr<Port>, bool);
void signal_drop ();
void drop ();
PBD::ScopedConnection drop_connection;
PBD::ScopedConnection engine_connection;

View File

@ -38,6 +38,7 @@ using namespace PBD;
PBD::Signal2<void,boost::shared_ptr<Port>, boost::shared_ptr<Port> > Port::PostDisconnect;
PBD::Signal0<void> Port::PortDrop;
PBD::Signal0<void> Port::PortSignalDrop;
bool Port::_connecting_blocked = false;
pframes_t Port::_global_port_buffer_offset = 0;
@ -75,6 +76,7 @@ Port::Port (std::string const & n, DataType t, PortFlags f)
}
PortDrop.connect_same_thread (drop_connection, boost::bind (&Port::drop, this));
PortSignalDrop.connect_same_thread (drop_connection, boost::bind (&Port::signal_drop, this));
port_manager->PortConnectedOrDisconnected.connect_same_thread (engine_connection,
boost::bind (&Port::port_connected_or_disconnected, this, _1, _3, _5));
}
@ -118,6 +120,12 @@ Port::set_pretty_name(const std::string& n)
return false;
}
void
Port::signal_drop ()
{
engine_connection.disconnect ();
}
void
Port::drop ()
{

View File

@ -591,6 +591,9 @@ Session::destroy ()
_state_of_the_state = StateOfTheState (CannotSave|Deletion);
/* stop autoconnecting */
auto_connect_thread_terminate ();
/* disconnect from any and all signals that we are connected to */
drop_connections ();
@ -613,6 +616,7 @@ Session::destroy ()
* callbacks from the engine any more.
*/
Port::PortSignalDrop (); /* EMIT SIGNAL */
Port::PortDrop (); /* EMIT SIGNAL */
ltc_tx_cleanup();
@ -725,8 +729,6 @@ Session::destroy ()
pthread_cond_destroy (&_rt_emit_cond);
pthread_mutex_destroy (&_rt_emit_mutex);
auto_connect_thread_terminate ();
pthread_cond_destroy (&_auto_connect_cond);
pthread_mutex_destroy (&_auto_connect_mutex);
@ -6791,12 +6793,12 @@ Session::auto_connect_thread_start ()
if (_ac_thread_active) {
return;
}
_ac_thread_active = true;
// clear queue
while (!_auto_connect_queue.empty ()) {
_auto_connect_queue.pop ();
}
_ac_thread_active = true;
if (pthread_create (&_auto_connect_thread, NULL, auto_connect_thread, this)) {
_ac_thread_active = false;
}
@ -6810,6 +6812,13 @@ Session::auto_connect_thread_terminate ()
}
_ac_thread_active = false;
{
Glib::Threads::Mutex::Lock lx (_auto_connect_queue_lock);
while (!_auto_connect_queue.empty ()) {
_auto_connect_queue.pop ();
}
}
if (pthread_mutex_lock (&_auto_connect_mutex) == 0) {
pthread_cond_signal (&_auto_connect_cond);
pthread_mutex_unlock (&_auto_connect_mutex);