summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2023-04-14 16:12:31 +0200
committerMikolaj Boc <mikolaj.boc@qt.io>2023-04-16 21:32:56 +0200
commitcb5f13e766cade954ffea4f6a62d7b9c81b5fb90 (patch)
tree594403819bf422bf5f0be9141390c8c443e51db3
parent1b5249d1186064cd320b36ef6df7128e2e9937f2 (diff)
downloadqtmultimedia-cb5f13e766cade954ffea4f6a62d7b9c81b5fb90.tar.gz
QSampleCache: Wait for load thread to finish before restarting it
One cannot rely on QThread::isRunning for checking whether the thread hasn't finished yet, as the thread might be quitting and still return true from isRunning. In that case, the thread won't process the sample load request that misses the start() call in this case. Fixes: QTBUG-109167 Pick-to: 6.5 Change-Id: I33382ad3d8a19ceb86857c51227e81a86a88eea7 Reviewed-by: Lars Knoll <lars@knoll.priv.no>
-rw-r--r--src/multimedia/audio/qsamplecache_p.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/multimedia/audio/qsamplecache_p.cpp b/src/multimedia/audio/qsamplecache_p.cpp
index e753402fb..825c79685 100644
--- a/src/multimedia/audio/qsamplecache_p.cpp
+++ b/src/multimedia/audio/qsamplecache_p.cpp
@@ -130,6 +130,7 @@ QSample* QSampleCache::requestSample(const QUrl& url)
{
//lock and add first to make sure live loadingThread will not be killed during this function call
m_loadingMutex.lock();
+ const bool needsThreadStart = m_loadingRefCount == 0;
m_loadingRefCount++;
m_loadingMutex.unlock();
@@ -138,8 +139,11 @@ QSample* QSampleCache::requestSample(const QUrl& url)
QMap<QUrl, QSample*>::iterator it = m_samples.find(url);
QSample* sample;
if (it == m_samples.end()) {
- if (!m_loadingThread.isRunning())
+ if (needsThreadStart) {
+ // Previous thread might be finishing, need to wait for it. If not, this is a no-op.
+ m_loadingThread.wait();
m_loadingThread.start();
+ }
sample = new QSample(url, this);
m_samples.insert(url, sample);
#if QT_CONFIG(thread)