From d7f631757a0f981f4e7219ec1353b09f3cf80d52 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 31 May 2023 01:14:53 +0200 Subject: [PATCH] Tweak Source removal * Do not emit signal with source-lock mutex held * explicitly drop references when called directly; notably from EditorSources::remove_selected_sources --- libs/ardour/ardour/session.h | 2 +- libs/ardour/session.cc | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index fe48b7afe1..0233514383 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -853,7 +853,7 @@ public: static PBD::Signal4 Exported; void add_source (std::shared_ptr); - void remove_source (std::weak_ptr); + void remove_source (std::weak_ptr, bool drop_references = true); void cleanup_regions(); bool can_cleanup_peakfiles () const; diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 653e3487c5..77f80fbb08 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4613,14 +4613,14 @@ Session::add_source (std::shared_ptr source) } } - source->DropReferences.connect_same_thread (*this, boost::bind (&Session::remove_source, this, std::weak_ptr (source))); + source->DropReferences.connect_same_thread (*this, boost::bind (&Session::remove_source, this, std::weak_ptr (source), false)); SourceAdded (std::weak_ptr (source)); /* EMIT SIGNAL */ } } void -Session::remove_source (std::weak_ptr src) +Session::remove_source (std::weak_ptr src, bool drop_references) { if (deletion_in_progress ()) { return; @@ -4638,12 +4638,21 @@ Session::remove_source (std::weak_ptr src) if ((i = sources.find (source->id())) != sources.end()) { sources.erase (i); - SourceRemoved (src); /* EMIT SIGNAL */ } else { return; } } + SourceRemoved (src); /* EMIT SIGNAL */ + if (drop_references) { + /* It would not matter to recurse here, the + * source was already removed from the sources. + * But there is no need to take the source_lock again. + */ + source->drop_references (); + } + assert (!source->used ()); + if (source->empty ()) { /* No need to save when empty sources are removed. * This is likely due to disk-writer initial dummies