Tweak Source removal

* Do not emit signal with source-lock mutex held
* explicitly drop references when called directly; notably from
  EditorSources::remove_selected_sources
This commit is contained in:
Robin Gareus 2023-05-31 01:14:53 +02:00
parent 331efe835f
commit d7f631757a
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 13 additions and 4 deletions

View File

@ -853,7 +853,7 @@ public:
static PBD::Signal4<void, std::string, std::string, bool, samplepos_t> Exported;
void add_source (std::shared_ptr<Source>);
void remove_source (std::weak_ptr<Source>);
void remove_source (std::weak_ptr<Source>, bool drop_references = true);
void cleanup_regions();
bool can_cleanup_peakfiles () const;

View File

@ -4613,14 +4613,14 @@ Session::add_source (std::shared_ptr<Source> source)
}
}
source->DropReferences.connect_same_thread (*this, boost::bind (&Session::remove_source, this, std::weak_ptr<Source> (source)));
source->DropReferences.connect_same_thread (*this, boost::bind (&Session::remove_source, this, std::weak_ptr<Source> (source), false));
SourceAdded (std::weak_ptr<Source> (source)); /* EMIT SIGNAL */
}
}
void
Session::remove_source (std::weak_ptr<Source> src)
Session::remove_source (std::weak_ptr<Source> src, bool drop_references)
{
if (deletion_in_progress ()) {
return;
@ -4638,12 +4638,21 @@ Session::remove_source (std::weak_ptr<Source> 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