Skip to content

Commit

Permalink
opt:add mutex to the wordfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Feb 13, 2025
1 parent 44154f0 commit 460e741
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/wordfinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "wordfinder.hh"
#include "folding.hh"
#include <map>
#include <QMutexLocker>


using std::vector;
Expand Down Expand Up @@ -112,6 +113,7 @@ void WordFinder::startSearch()
return; // Search was probably cancelled
}

QMutexLocker locker( &mutex );
// Clear the requests just in case
queuedRequests.clear();
finishedRequests.clear();
Expand Down Expand Up @@ -177,13 +179,15 @@ void WordFinder::cancel()

void WordFinder::clear()
{
QMutexLocker locker( &mutex );
cancel();
queuedRequests.clear();
finishedRequests.clear();
}

void WordFinder::requestFinished()
{
QMutexLocker locker( &mutex );
bool newResults = false;

// See how many new requests have finished, and if we have any new results
Expand Down Expand Up @@ -288,6 +292,7 @@ void WordFinder::updateResults()
if ( updateResultsTimer.isActive() ) {
updateResultsTimer.stop(); // Can happen when we were done before it'd expire
}
QMutexLocker locker( &mutex );

std::u32string original = Folding::applySimpleCaseOnly( allWordWritings[ 0 ] );

Expand Down
1 change: 1 addition & 0 deletions src/wordfinder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private:
bool searchResultsUncertain;
std::list< sptr< Dictionary::WordSearchRequest > > queuedRequests, finishedRequests;
bool searchInProgress;
QMutex mutex;

QTimer updateResultsTimer;

Expand Down

0 comments on commit 460e741

Please sign in to comment.