summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2023-04-14 16:12:31 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-04-16 20:00:32 +0000
commitf53f31d9b9c5b9f21de392cc8b155e6ee2eec3fd (patch)
tree191735b47ab5f8768381e43aa70e52c2dc80293c
parent7d9e25e410dbe486b84d5d661ba74103274d878e (diff)
downloadqtmultimedia-f53f31d9b9c5b9f21de392cc8b155e6ee2eec3fd.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 Change-Id: I33382ad3d8a19ceb86857c51227e81a86a88eea7 Reviewed-by: Lars Knoll <lars@knoll.priv.no> (cherry picked from commit cb5f13e766cade954ffea4f6a62d7b9c81b5fb90) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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)