Fix race condition and deadlock in the version plugin

when listing directories is slow.

BUG: 302264
FIXED-IN: 4.9.3
This commit is contained in:
Simeon Bird 2012-10-19 21:04:55 -04:00
parent 9685cba808
commit b4c01c00a9

View file

@ -45,10 +45,12 @@ UpdateItemStatesThread::~UpdateItemStatesThread()
void UpdateItemStatesThread::setData(KVersionControlPlugin* plugin,
const QList<VersionControlObserver::ItemState>& itemStates)
{
QMutexLocker itemLocker(&m_itemMutex);
m_itemStates = itemStates;
// The locks are taken in the same order as in run()
// to avoid potential deadlock.
QMutexLocker pluginLocker(m_globalPluginMutex);
QMutexLocker itemLocker(&m_itemMutex);
m_itemStates = itemStates;
m_plugin = plugin;
}
@ -58,11 +60,12 @@ void UpdateItemStatesThread::run()
Q_ASSERT(m_plugin);
QMutexLocker itemLocker(&m_itemMutex);
const QString directory = m_itemStates.first().item.url().directory(KUrl::AppendTrailingSlash);
m_retrievedItems = false;
itemLocker.unlock();
QMutexLocker pluginLocker(m_globalPluginMutex);
m_retrievedItems = false;
if (m_plugin->beginRetrieval(directory)) {
itemLocker.relock();
const int count = m_itemStates.count();