diff options
author | Christian Stenger <christian.stenger@theqtcompany.com> | 2014-12-09 14:02:41 +0100 |
---|---|---|
committer | Christian Stenger <christian.stenger@theqtcompany.com> | 2014-12-09 15:04:46 +0200 |
commit | cda4227a62d763c568dcf242bc2a816eeedc321d (patch) | |
tree | 1002a3ae0ea9279023870c19c65c26d1fad3b575 | |
parent | ac24550a22ad59712e4cb5ea9955583c25101839 (diff) | |
download | qt-creator-cda4227a62d763c568dcf242bc2a816eeedc321d.tar.gz |
Re-do the usage of QWriteLocker
Only lock if necessary to avoid dead-lock situations.
Change-Id: I39d1158749131a72805e55f28aba79e1827f158b
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
-rw-r--r-- | plugins/autotest/testresultmodel.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/plugins/autotest/testresultmodel.cpp b/plugins/autotest/testresultmodel.cpp index 78dbf1d883..6ccc3946ff 100644 --- a/plugins/autotest/testresultmodel.cpp +++ b/plugins/autotest/testresultmodel.cpp @@ -54,7 +54,7 @@ QModelIndex TestResultModel::parent(const QModelIndex &) const int TestResultModel::rowCount(const QModelIndex &parent) const { - // do not use the QReadLocker here or this will produce a deadlock + QReadLocker lock(&m_rwLock); return parent.isValid() ? 0 : m_testResults.size(); } @@ -122,19 +122,21 @@ void TestResultModel::addTestResult(const TestResult &testResult) int position = m_testResults.size(); rLock.unlock(); - QWriteLocker wLock(&m_rwLock); if (hasCurrentTestMssg && isCurrentTestMssg) { beginRemoveRows(QModelIndex(), position, position); + QWriteLocker wLock(&m_rwLock); m_testResults.replace(position - 1, testResult); + wLock.unlock(); endRemoveRows(); } else { if (!isCurrentTestMssg && position) // decrement only if at least one other item --position; beginInsertRows(QModelIndex(), position, position); + QWriteLocker wLock(&m_rwLock); m_testResults.insert(position, testResult); + wLock.unlock(); endInsertRows(); } - wLock.unlock(); if (!isCurrentTestMssg) { int count = m_testResultCount.value(testResult.result(), 0); @@ -148,10 +150,11 @@ void TestResultModel::removeCurrentTestMessage() { QReadLocker rLock(&m_rwLock); if (m_availableResultTypes.contains(ResultType::MESSAGE_CURRENT_TEST)) { + beginRemoveRows(QModelIndex(), m_testResults.size() - 1, m_testResults.size() - 1); rLock.unlock(); QWriteLocker wLock(&m_rwLock); - beginRemoveRows(QModelIndex(), m_testResults.size() - 1, m_testResults.size() - 1); m_testResults.removeLast(); + wLock.unlock(); endRemoveRows(); m_availableResultTypes.remove(ResultType::MESSAGE_CURRENT_TEST); } |