diff options
author | ck <qt-info@nokia.com> | 2009-07-06 08:20:02 (GMT) |
---|---|---|
committer | ck <qt-info@nokia.com> | 2009-07-06 08:20:02 (GMT) |
commit | bf5112c6673d32cbaad33c388d38690264adf107 (patch) | |
tree | 6c05aa50a0778ff8db97143b706f226b4b316a04 /tools/assistant/lib/qhelpsearchindexreader_clucene.cpp | |
parent | 8915977e56b58c4631dfb2b8616585b664e55f38 (diff) | |
download | Qt-bf5112c6673d32cbaad33c388d38690264adf107.zip Qt-bf5112c6673d32cbaad33c388d38690264adf107.tar.gz Qt-bf5112c6673d32cbaad33c388d38690264adf107.tar.bz2 |
Fixed race condition in search module.
Task-number: 257441
Reviewed-by: kh
Diffstat (limited to 'tools/assistant/lib/qhelpsearchindexreader_clucene.cpp')
-rw-r--r-- | tools/assistant/lib/qhelpsearchindexreader_clucene.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp index 227e558..867e060 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp @@ -86,8 +86,8 @@ void QHelpSearchIndexReader::cancelSearching() void QHelpSearchIndexReader::search(const QString &collectionFile, const QString &indexFilesFolder, const QList<QHelpSearchQuery> &queryList) { - QMutexLocker lock(&mutex); - + wait(); + this->hitList.clear(); this->m_cancel = false; this->m_query = queryList; @@ -99,12 +99,18 @@ void QHelpSearchIndexReader::search(const QString &collectionFile, const QString int QHelpSearchIndexReader::hitsCount() const { + QMutexLocker lock(&mutex); return hitList.count(); } -QHelpSearchEngine::SearchHit QHelpSearchIndexReader::hit(int index) const +QList<QHelpSearchEngine::SearchHit> QHelpSearchIndexReader::hits(int start, + int end) const { - return hitList.at(index); + QList<QHelpSearchEngine::SearchHit> hits; + QMutexLocker lock(&mutex); + for (int i = start; i < end && i < hitList.count(); ++i) + hits.append(hitList.at(i)); + return hits; } void QHelpSearchIndexReader::run() @@ -135,7 +141,7 @@ void QHelpSearchIndexReader::run() if(QCLuceneIndexReader::indexExists(indexPath)) { mutex.lock(); if (m_cancel) { - mutex.unlock(); + mutex.unlock(); return; } mutex.unlock(); @@ -213,7 +219,9 @@ void QHelpSearchIndexReader::run() #if !defined(QT_NO_EXCEPTIONS) } catch(...) { + mutex.lock(); hitList.clear(); + mutex.unlock(); emit searchingFinished(0); } #endif @@ -416,8 +424,9 @@ void QHelpSearchIndexReader::boostSearchHits(const QHelpEngineCore &engine, boostedList.append(it.value()); } while (it != hitMap.constBegin()); boostedList += hitList.mid(count, hitList.count()); - + mutex.lock(); hitList = boostedList; + mutex.unlock(); } } |