Fix crash due to concurrent sndfile access

Peak files are built int background which can happen concurrently
to estimating tempo. Notably when importing large .flac files
this can cause a crash because libsndfile API does not allow
for concurrent use of the same SNDFILE object.
This commit is contained in:
Robin Gareus
2025-10-26 15:10:46 +01:00
parent 02af9cb3d6
commit 9786e6035f
2 changed files with 15 additions and 3 deletions

View File

@@ -135,7 +135,10 @@ AudioSource::~AudioSource ()
void
AudioSource::estimate_tempo ()
{
#ifndef NDEBUG
/* CALLER MUST HOLD WRITER LOCK */
assert (!_lock.writer_trylock());
#endif
const samplecnt_t ten_seconds = _session.sample_rate() * 10;

View File

@@ -259,7 +259,10 @@ SourceFactory::createExternal (DataType type, Session& s, const string& path,
throw failed_constructor ();
}
ret->check_for_analysis_data_on_disk ();
src->estimate_tempo ();
{
Source::WriterLock lm (src->mutex ());
src->estimate_tempo ();
}
if (announce) {
SourceCreated (ret);
}
@@ -276,7 +279,10 @@ SourceFactory::createExternal (DataType type, Session& s, const string& path,
throw failed_constructor ();
}
ret->check_for_analysis_data_on_disk ();
src->estimate_tempo ();
{
Source::WriterLock lm (src->mutex ());
src->estimate_tempo ();
}
if (announce) {
SourceCreated (ret);
}
@@ -425,7 +431,10 @@ SourceFactory::createFromPlaylist (DataType type, Session& s, std::shared_ptr<Pl
}
ret->check_for_analysis_data_on_disk ();
src->estimate_tempo ();
{
Source::WriterLock lm (src->mutex ());
src->estimate_tempo ();
}
SourceCreated (ret);
return ret;
}