From 18665ec2cd6d0cb40bff8f1e32cf71bb43ace49a Mon Sep 17 00:00:00 2001 From: zhangpengfei Date: Mon, 11 Jan 2021 18:36:04 +0800 Subject: [PATCH] Add lock in deconstruction of index-generator. --- libsearch/index/file-searcher.cpp | 9 +++++---- libsearch/index/index-generator.cpp | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libsearch/index/file-searcher.cpp b/libsearch/index/file-searcher.cpp index 145ba68..d666657 100644 --- a/libsearch/index/file-searcher.cpp +++ b/libsearch/index/file-searcher.cpp @@ -22,10 +22,6 @@ FileSearcher::~FileSearcher() void FileSearcher::onKeywordSearch(QString keyword,QQueue *searchResultFile,QQueue *searchResultDir,QQueue> *searchResultContent) { - m_search_result_file = searchResultFile; - m_search_result_dir = searchResultDir; - m_search_result_content = searchResultContent; - m_mutex1.lock(); ++uniqueSymbol1; m_mutex1.unlock(); @@ -35,6 +31,11 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue *searchResult m_mutex3.lock(); ++uniqueSymbol3; m_mutex3.unlock(); + + m_search_result_file = searchResultFile; + m_search_result_dir = searchResultDir; + m_search_result_content = searchResultContent; + //file QtConcurrent::run([&, uniqueSymbol1](){ if(!m_search_result_file->isEmpty()) diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index 466f253..a99bd04 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -120,6 +120,7 @@ IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent) IndexGenerator::~IndexGenerator() { + QMutexLocker locker(&m_mutex); qDebug() << "~IndexGenerator"; if(m_datebase_path) delete m_datebase_path;