summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorck <qt-info@nokia.com>2009-07-06 08:20:02 (GMT)
committerck <qt-info@nokia.com>2009-07-06 08:20:02 (GMT)
commitbf5112c6673d32cbaad33c388d38690264adf107 (patch)
tree6c05aa50a0778ff8db97143b706f226b4b316a04 /tools
parent8915977e56b58c4631dfb2b8616585b664e55f38 (diff)
downloadQt-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')
-rw-r--r--tools/assistant/lib/qhelpsearchengine.cpp10
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_clucene.cpp21
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_clucene_p.h5
3 files changed, 21 insertions, 15 deletions
diff --git a/tools/assistant/lib/qhelpsearchengine.cpp b/tools/assistant/lib/qhelpsearchengine.cpp
index 9faafe0..15f7f9e 100644
--- a/tools/assistant/lib/qhelpsearchengine.cpp
+++ b/tools/assistant/lib/qhelpsearchengine.cpp
@@ -96,6 +96,7 @@ private:
delete indexWriter;
}
+
int hitsCount() const
{
int count = 0;
@@ -107,12 +108,9 @@ private:
QList<QHelpSearchEngine::SearchHit> hits(int start, int end) const
{
- QList<QHelpSearchEngine::SearchHit> returnValue;
- if (indexReader) {
- for (int i = start; i < end && i < hitsCount(); ++i)
- returnValue.append(indexReader->hit(i));
- }
- return returnValue;
+ return indexReader ?
+ indexReader->hits(start, end) :
+ QList<QHelpSearchEngine::SearchHit>();
}
void updateIndex(bool reindex = false)
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();
}
}
diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
index 47af43f..e7ac0eb 100644
--- a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
+++ b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
@@ -85,9 +85,8 @@ public:
void search(const QString &collectionFile,
const QString &indexFilesFolder,
const QList<QHelpSearchQuery> &queryList);
-
int hitsCount() const;
- QHelpSearchEngine::SearchHit hit(int index) const;
+ QList<QHelpSearchEngine::SearchHit> hits(int start, int end) const;
signals:
void searchingStarted();
@@ -105,7 +104,7 @@ private:
const QList<QHelpSearchQuery> &queryList);
private:
- QMutex mutex;
+ mutable QMutex mutex;
QList<QHelpSearchEngine::SearchHit> hitList;
QWaitCondition waitCondition;