From 3c02fb74994131eeca0546619a05f4fa93a1a898 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sun, 19 Jun 2022 10:16:31 +0800 Subject: [PATCH 1/4] bump alpha version to 22.6.22 --- .github/workflows/AutoTag.yml | 2 +- .github/workflows/macos-6.2.yml | 2 +- .github/workflows/macos.yml | 2 +- .github/workflows/ubuntu-6.2.yml | 2 +- .github/workflows/ubuntu-PR-check.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- .github/workflows/windows-6.2.yml | 2 +- .github/workflows/windows-PR-check.yml | 2 +- .github/workflows/windows.yml | 2 +- goldendict.pro | 4 ++-- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/AutoTag.yml b/.github/workflows/AutoTag.yml index b2ff9516b..70f897dad 100644 --- a/.github/workflows/AutoTag.yml +++ b/.github/workflows/AutoTag.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest env: - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true diff --git a/.github/workflows/macos-6.2.yml b/.github/workflows/macos-6.2.yml index 26accb9b1..01cd0970f 100644 --- a/.github/workflows/macos-6.2.yml +++ b/.github/workflows/macos-6.2.yml @@ -29,7 +29,7 @@ jobs: qt_arch: [clang_64] env: targetName: GoldenDict - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 6da782571..34811893c 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -30,7 +30,7 @@ jobs: qt_arch: [clang_64] env: targetName: GoldenDict - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true diff --git a/.github/workflows/ubuntu-6.2.yml b/.github/workflows/ubuntu-6.2.yml index b18377d6a..1d843960a 100644 --- a/.github/workflows/ubuntu-6.2.yml +++ b/.github/workflows/ubuntu-6.2.yml @@ -30,7 +30,7 @@ jobs: qt_ver: [6.3.1] qt_arch: [gcc_64] env: - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/ubuntu-PR-check.yml b/.github/workflows/ubuntu-PR-check.yml index 781c5225f..f5fa9145a 100644 --- a/.github/workflows/ubuntu-PR-check.yml +++ b/.github/workflows/ubuntu-PR-check.yml @@ -26,7 +26,7 @@ jobs: qt_ver: [5.15.2,6.2.4] qt_arch: [gcc_64] env: - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index d887d3743..93589df60 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -30,7 +30,7 @@ jobs: qt_ver: [5.15.2] qt_arch: [gcc_64] env: - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/windows-6.2.yml b/.github/workflows/windows-6.2.yml index 3ee25c986..9759adcc1 100644 --- a/.github/workflows/windows-6.2.yml +++ b/.github/workflows/windows-6.2.yml @@ -31,7 +31,7 @@ jobs: qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/windows-PR-check.yml b/.github/workflows/windows-PR-check.yml index 9a0724d6b..5a9b4b3ac 100644 --- a/.github/workflows/windows-PR-check.yml +++ b/.github/workflows/windows-PR-check.yml @@ -29,7 +29,7 @@ jobs: env: targetName: GoldenDict.exe - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2e6cfb78f..87bdd3351 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -32,7 +32,7 @@ jobs: qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe - version: 22.5.22 + version: 22.6.22 version-suffix: alpha prerelease: true # 步骤 diff --git a/goldendict.pro b/goldendict.pro index 7ab55f538..76ea54e70 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = goldendict -VERSION = 22.5.22-alpha +VERSION = 22.6.22-alpha # Generate version file. We do this here and in a build rule described later. # The build rule is required since qmake isn't run each time the project is @@ -93,7 +93,7 @@ win32 { TARGET = GoldenDict win32-msvc* { - VERSION = 22.5.22 # VS does not recognize 22.number.alpha,cause errors during compilation under MSVC++ + VERSION = 22.6.22 # VS does not recognize 22.number.alpha,cause errors during compilation under MSVC++ DEFINES += __WIN32 _CRT_SECURE_NO_WARNINGS contains(QMAKE_TARGET.arch, x86_64) { DEFINES += NOMINMAX __WIN64 From 4edd3b3987ff9126a4e30d26f363487e2b82e2ab Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sun, 19 Jun 2022 13:26:41 +0800 Subject: [PATCH 2/4] add mutex to scopedmemmap --- ftshelpers.cc | 1 + mdx.cc | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ftshelpers.cc b/ftshelpers.cc index 29bf509ac..849fd7ba7 100644 --- a/ftshelpers.cc +++ b/ftshelpers.cc @@ -807,6 +807,7 @@ void FTSResultsRequest::combinedIndexSearch( BtreeIndexing::BtreeIndex & ftsInde { if( Utils::AtomicInt::loadAcquire( isCancelled ) ) { + Mutex::Lock _( dataMutex ); sets << tmp; return; } diff --git a/mdx.cc b/mdx.cc index b096959c0..448b7a1fb 100644 --- a/mdx.cc +++ b/mdx.cc @@ -173,17 +173,23 @@ class IndexedMdd: public BtreeIndexing::BtreeIndex return false; } - ScopedMemMap compressed( mddFile, indexEntry.compressedBlockPos, indexEntry.compressedBlockSize ); - if ( !compressed.startAddress() ) - { - return false; - } - QByteArray decompressed; - if ( !MdictParser::parseCompressedBlock( indexEntry.compressedBlockSize, ( char * )compressed.startAddress(), - indexEntry.decompressedBlockSize, decompressed ) ) + { - return false; + Mutex::Lock _( idxMutex ); + ScopedMemMap compressed( mddFile, indexEntry.compressedBlockPos, indexEntry.compressedBlockSize ); + if( !compressed.startAddress() ) + { + return false; + } + + if( !MdictParser::parseCompressedBlock( indexEntry.compressedBlockSize, + (char *)compressed.startAddress(), + indexEntry.decompressedBlockSize, + decompressed ) ) + { + return false; + } } result.resize( indexEntry.recordSize ); From 6ff042d56f9a31a43f793f4c7537be3c9d88b3e0 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sun, 19 Jun 2022 14:56:18 +0800 Subject: [PATCH 3/4] fulltext search can not cancel --- ftshelpers.cc | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/ftshelpers.cc b/ftshelpers.cc index 849fd7ba7..680ace671 100644 --- a/ftshelpers.cc +++ b/ftshelpers.cc @@ -443,27 +443,19 @@ void FTSResultsRequest::checkArticles( QVector< uint32_t > const & offsets, QStringList const & words, QRegExp const & searchRegexp ) { - const int parallel_count = QThread::idealThreadCount()/2; - QSemaphore sem( parallel_count < 1 ? 1 : parallel_count ); - - QFutureSynchronizer< void > synchronizer; + // const int parallel_count = QThread::idealThreadCount()/2; + // QSemaphore sem( parallel_count < 1 ? 1 : parallel_count ); + // + // QFutureSynchronizer< void > synchronizer; const auto searchRegularExpression = createMatchRegex( searchRegexp ); for( auto & address : offsets ) { if( Utils::AtomicInt::loadAcquire( isCancelled ) ) { - synchronizer.setCancelOnWait(true); return; } - sem.acquire(); - QFuture< void > f = QtConcurrent::run( - [ =,&sem ]() - { - QSemaphoreReleaser releaser( sem ); - checkSingleArticle( address, words, searchRegularExpression ); - } ); - synchronizer.addFuture( f ); + checkSingleArticle( address, words, searchRegularExpression ); } } @@ -723,7 +715,18 @@ void FTSResultsRequest::indexSearch( BtreeIndexing::BtreeIndex & ftsIndex, } }; // int n = indexWords.length(); - QtConcurrent::blockingMap( indexWords, findLinks ); + // QtConcurrent::blockingMap( indexWords, findLinks ); + + for(QString word:indexWords) + { + if( Utils::AtomicInt::loadAcquire( isCancelled ) ) + { + return; + } + findLinks( word ); + } + + // blocked execution. int i = 0; for( auto & elem : addressLists ) @@ -840,7 +843,20 @@ void FTSResultsRequest::combinedIndexSearch( BtreeIndexing::BtreeIndex & ftsInde sets << tmp; } }; - QtConcurrent::blockingMap( wordsList, fn_wordLink ); + // QtConcurrent::blockingMap( wordsList, fn_wordLink ); + + { + + for(const auto & word : wordsList ) + { + if( Utils::AtomicInt::loadAcquire( isCancelled ) ) + { + return; + } + fn_wordLink( word ); + } + } + //blocked execution. int i = 0; for( auto & elem : sets ) From bd02d65ecc30a9e875da20af8268ade8b1a23e7c Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sun, 19 Jun 2022 20:24:34 +0800 Subject: [PATCH 4/4] concurrent run will crash application --- dsl.cc | 12 ++++++++++-- epwing.cc | 10 +++++++--- ftshelpers.hh | 6 +++++- mdx.cc | 13 ++++++++++--- zim.cc | 11 +++++++++-- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/dsl.cc b/dsl.cc index 164a42fe4..b7ffbf34f 100644 --- a/dsl.cc +++ b/dsl.cc @@ -56,6 +56,8 @@ // For SVG handling #include +#include + #include "utils.hh" namespace Dsl { @@ -1561,6 +1563,7 @@ class DslArticleRequest: public Dictionary::DataRequest QAtomicInt isCancelled; QSemaphore hasExited; + QFuture< void > f; public: @@ -1569,7 +1572,8 @@ class DslArticleRequest: public Dictionary::DataRequest DslDictionary & dict_, bool ignoreDiacritics_ ): word( word_ ), alts( alts_ ), dict( dict_ ), ignoreDiacritics( ignoreDiacritics_ ) { - QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); + f = QtConcurrent::run( [ this ]() { this->run(); } ); + // QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); } void run(); @@ -1582,6 +1586,7 @@ class DslArticleRequest: public Dictionary::DataRequest ~DslArticleRequest() { isCancelled.ref(); + f.waitForFinished(); //hasExited.acquire(); } }; @@ -1733,6 +1738,7 @@ class DslResourceRequest: public Dictionary::DataRequest QAtomicInt isCancelled; QSemaphore hasExited; + QFuture< void > f; public: @@ -1741,7 +1747,8 @@ class DslResourceRequest: public Dictionary::DataRequest dict( dict_ ), resourceName( resourceName_ ) { - QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); + f = QtConcurrent::run( [ this ]() { this->run(); } ); + // QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); } void run(); @@ -1754,6 +1761,7 @@ class DslResourceRequest: public Dictionary::DataRequest ~DslResourceRequest() { isCancelled.ref(); + f.waitForFinished(); //hasExited.acquire(); } }; diff --git a/epwing.cc b/epwing.cc index 2f9ef6077..bdb1d28be 100644 --- a/epwing.cc +++ b/epwing.cc @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -461,6 +462,7 @@ class EpwingArticleRequest: public Dictionary::DataRequest QAtomicInt isCancelled; QSemaphore hasExited; + QFuture< void > f; public: @@ -469,8 +471,9 @@ class EpwingArticleRequest: public Dictionary::DataRequest EpwingDictionary & dict_, bool ignoreDiacritics_ ): word( word_ ), alts( alts_ ), dict( dict_ ), ignoreDiacritics( ignoreDiacritics_ ) { - QThreadPool::globalInstance()->start( - new EpwingArticleRequestRunnable( *this, hasExited ) ); + f = QtConcurrent::run( [ this ]() { this->run(); } ); + // QThreadPool::globalInstance()->start( + // new EpwingArticleRequestRunnable( *this, hasExited ) ); } void run(); // Run from another thread by EpwingArticleRequestRunnable @@ -483,7 +486,8 @@ class EpwingArticleRequest: public Dictionary::DataRequest ~EpwingArticleRequest() { isCancelled.ref(); - hasExited.acquire(); + f.waitForFinished(); + // hasExited.acquire(); } }; diff --git a/ftshelpers.hh b/ftshelpers.hh index 5a5ac6ea0..cf02a06c0 100644 --- a/ftshelpers.hh +++ b/ftshelpers.hh @@ -10,6 +10,7 @@ #include #include #include +#include #include "dictionary.hh" #include "btreeidx.hh" @@ -83,6 +84,7 @@ class FTSResultsRequest : public Dictionary::DataRequest QAtomicInt isCancelled; QAtomicInt results; + QFuture< void > f; QList< FTS::FtsHeadword > * foundHeadwords; @@ -135,7 +137,8 @@ public: foundHeadwords = new QList< FTS::FtsHeadword >; results = 0; - QThreadPool::globalInstance()->start( [ this ]() { this->run(); }, -100 ); + f = QtConcurrent::run( [ this ]() { this->run(); } ); + // QThreadPool::globalInstance()->start( [ this ]() { this->run(); }, -100 ); } void run(); @@ -148,6 +151,7 @@ public: ~FTSResultsRequest() { isCancelled.ref(); + f.waitForFinished(); if( foundHeadwords ) delete foundHeadwords; } diff --git a/mdx.cc b/mdx.cc index 448b7a1fb..fb1df58fd 100644 --- a/mdx.cc +++ b/mdx.cc @@ -43,6 +43,7 @@ #include "tiff.hh" #include "utils.hh" #include "base/globalregex.hh" +#include namespace Mdx { @@ -533,6 +534,7 @@ class MdxArticleRequest: public Dictionary::DataRequest QAtomicInt isCancelled; QSemaphore hasExited; + QFuture< void > f; public: @@ -545,7 +547,8 @@ class MdxArticleRequest: public Dictionary::DataRequest dict( dict_ ), ignoreDiacritics( ignoreDiacritics_ ) { - QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); + f = QtConcurrent::run( [ this ]() { this->run(); } ); + // QThreadPool::globalInstance()->start( ); } void run(); @@ -558,7 +561,8 @@ class MdxArticleRequest: public Dictionary::DataRequest ~MdxArticleRequest() { isCancelled.ref(); - //hasExited.acquire(); + f.waitForFinished(); + // hasExited.acquire(); } }; @@ -687,6 +691,7 @@ class MddResourceRequest: public Dictionary::DataRequest wstring resourceName; QAtomicInt isCancelled; QSemaphore hasExited; + QFuture< void > f; public: @@ -695,7 +700,8 @@ class MddResourceRequest: public Dictionary::DataRequest dict( dict_ ), resourceName( Utf8::decode( resourceName_ ) ) { - QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); + f = QtConcurrent::run( [ this ]() { this->run(); } ); + // QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); } void run(); @@ -708,6 +714,7 @@ class MddResourceRequest: public Dictionary::DataRequest ~MddResourceRequest() { isCancelled.ref(); + f.waitForFinished(); //hasExited.acquire(); } }; diff --git a/zim.cc b/zim.cc index 6dc8a9b14..de827bfcf 100644 --- a/zim.cc +++ b/zim.cc @@ -41,6 +41,7 @@ #include #include #include +#include namespace Zim { @@ -1248,6 +1249,7 @@ class ZimArticleRequest: public Dictionary::DataRequest QAtomicInt isCancelled; QSemaphore hasExited; + QFuture< void > f; public: @@ -1256,7 +1258,8 @@ class ZimArticleRequest: public Dictionary::DataRequest ZimDictionary & dict_, bool ignoreDiacritics_ ): word( word_ ), alts( alts_ ), dict( dict_ ), ignoreDiacritics( ignoreDiacritics_ ) { - QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); + f = QtConcurrent::run( [ this ]() { this->run(); } ); + // QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); } void run(); @@ -1269,6 +1272,7 @@ class ZimArticleRequest: public Dictionary::DataRequest ~ZimArticleRequest() { isCancelled.ref(); + f.waitForFinished(); //hasExited.acquire(); } }; @@ -1421,11 +1425,13 @@ class ZimResourceRequest: public Dictionary::DataRequest QAtomicInt isCancelled; QSemaphore hasExited; + QFuture< void > f; public: ZimResourceRequest(ZimDictionary &dict_, string const &resourceName_) : dict(dict_), resourceName(resourceName_) { - QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); + f = QtConcurrent::run( [ this ]() { this->run(); } ); + // QThreadPool::globalInstance()->start( [ this ]() { this->run(); } ); } void run(); @@ -1438,6 +1444,7 @@ class ZimResourceRequest: public Dictionary::DataRequest ~ZimResourceRequest() { isCancelled.ref(); + f.waitForFinished(); //hasExited.acquire(); } };