From: Jean-Baptiste Mardelle Date: Wed, 12 Oct 2011 20:59:00 +0000 (+0000) Subject: Fix possible concurrency issue in thumbs X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=36422ee557390ca43fcc015688a2720fbd05437b;p=kdenlive Fix possible concurrency issue in thumbs svn path=/trunk/kdenlive/; revision=5953 --- diff --git a/src/kthumb.cpp b/src/kthumb.cpp index b26b5f1a..2369dc37 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -74,7 +74,9 @@ void KThumb::setProducer(Mlt::Producer *producer) m_intraFramesQueue.clear(); m_future.waitForFinished(); m_intra.waitForFinished(); + m_mutex.lock(); m_producer = producer; + m_mutex.unlock(); // FIXME: the profile() call leaks an object, but trying to free // it leads to a double-free in Profile::~Profile() if (producer) { @@ -131,7 +133,9 @@ void KThumb::doGetThumbs() while (!m_requestedThumbs.isEmpty()) { int frame = m_requestedThumbs.takeFirst(); if (frame != -1) { + m_mutex.lock(); QImage img = getFrame(m_producer, frame, swidth, dwidth, theight); + m_mutex.unlock(); emit thumbReady(frame, img); } } @@ -139,7 +143,10 @@ void KThumb::doGetThumbs() QPixmap KThumb::extractImage(int frame, int width, int height) { - return QPixmap::fromImage(getFrame(m_producer, frame, (int) (height * m_ratio + 0.5), width, height)); + m_mutex.lock(); + QImage img = getFrame(m_producer, frame, (int) (height * m_ratio + 0.5), width, height); + m_mutex.unlock(); + return QPixmap::fromImage(img); } //static @@ -483,10 +490,12 @@ void KThumb::slotGetIntraThumbs() while (!m_intraFramesQueue.isEmpty()) { int pos = m_intraFramesQueue.takeFirst(); if (!m_clipManager->pixmapCache->contains(path + QString::number(pos))) { + m_mutex.lock(); if (m_clipManager->pixmapCache->insertImage(path + QString::number(pos), getFrame(m_producer, pos, frameWidth, displayWidth, theight))) { addedThumbs = true; } else kDebug()<<"// INSERT FAILD FOR: "< m_intraFramesQueue; + QMutex m_mutex; void doGetThumbs(); signals: