diff options
author | Bea Lam <bea.lam@nokia.com> | 2011-08-11 13:26:15 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-13 00:01:12 +0200 |
commit | b631e1e4f245dc8ba4460bda6acb4ed1ef63bcdc (patch) | |
tree | dd549f4e1089b1fd81b993f2f8ab9c8a04b9ac3b | |
parent | 882831e39e882ea4a7f7b3e6ea719b969951778f (diff) |
Fix race condition in processJobs()
Don't modify list of running jobs when a job is aborted since the job
may have just started. Wait till the next time processJobs() is invoked
for a new job and discard the aborted job at that time.
(cherry picked from commit f55ecc080d0c5eca4e65a235c63ab13867c86874
in 4.8)
Task-number: QTBUG-20841
Change-Id: Icb4cd089505c0634d3fec023b52c61bbc878404f
Reviewed-on: http://codereview.qt.nokia.com/2837
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
-rw-r--r-- | src/declarative/util/qdeclarativexmllistmodel.cpp | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 7ac6c7679e..86e6e9e087 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -289,11 +289,8 @@ int QDeclarativeXmlQueryEngine::doQuery(QString query, QString namespaces, QByte void QDeclarativeXmlQueryEngine::abort(int id) { QMutexLocker ml(&m_mutex); - if (id != -1) { + if (id != -1) m_cancelledJobs.insert(id); - if (m_threadObject) - m_threadObject->processJobs(); - } } void QDeclarativeXmlQueryEngine::run() @@ -314,25 +311,19 @@ void QDeclarativeXmlQueryEngine::processJobs() QMutexLocker locker(&m_mutex); while (true) { - if (m_cancelledJobs.isEmpty() && m_jobs.isEmpty()) + if (m_jobs.isEmpty()) return; - if (!m_cancelledJobs.isEmpty()) { - for (QList<XmlQueryJob>::Iterator it = m_jobs.begin(); it != m_jobs.end(); ++it) { - int queryId = (*it).queryId; - if (m_cancelledJobs.remove(queryId)) - it = m_jobs.erase(it); - } - m_cancelledJobs.clear(); + XmlQueryJob currentJob = m_jobs.takeLast(); + while (m_cancelledJobs.remove(currentJob.queryId)) { + if (m_jobs.isEmpty()) + return; + currentJob = m_jobs.takeLast(); } - if (!m_jobs.isEmpty()) { - XmlQueryJob currentJob = m_jobs.takeLast(); - - locker.unlock(); - processQuery(¤tJob); - locker.relock(); - } + locker.unlock(); + processQuery(¤tJob); + locker.relock(); } } |