Skip to content

Commit

Permalink
fix version conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Jun 19, 2022
2 parents 1475590 + 2757e34 commit 59698b5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 35 deletions.
12 changes: 10 additions & 2 deletions dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
// For SVG handling
#include <QtSvg/QSvgRenderer>

#include <QtConcurrent>

#include "utils.hh"

namespace Dsl {
Expand Down Expand Up @@ -1561,6 +1563,7 @@ class DslArticleRequest: public Dictionary::DataRequest

QAtomicInt isCancelled;
QSemaphore hasExited;
QFuture< void > f;

public:

Expand All @@ -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();
Expand All @@ -1582,6 +1586,7 @@ class DslArticleRequest: public Dictionary::DataRequest
~DslArticleRequest()
{
isCancelled.ref();
f.waitForFinished();
//hasExited.acquire();
}
};
Expand Down Expand Up @@ -1733,6 +1738,7 @@ class DslResourceRequest: public Dictionary::DataRequest

QAtomicInt isCancelled;
QSemaphore hasExited;
QFuture< void > f;

public:

Expand All @@ -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();
Expand All @@ -1754,6 +1761,7 @@ class DslResourceRequest: public Dictionary::DataRequest
~DslResourceRequest()
{
isCancelled.ref();
f.waitForFinished();
//hasExited.acquire();
}
};
Expand Down
10 changes: 7 additions & 3 deletions epwing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QSemaphore>

#include <map>
#include <QtConcurrent>
#include <set>
#include <string>

Expand Down Expand Up @@ -461,6 +462,7 @@ class EpwingArticleRequest: public Dictionary::DataRequest

QAtomicInt isCancelled;
QSemaphore hasExited;
QFuture< void > f;

public:

Expand All @@ -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
Expand All @@ -483,7 +486,8 @@ class EpwingArticleRequest: public Dictionary::DataRequest
~EpwingArticleRequest()
{
isCancelled.ref();
hasExited.acquire();
f.waitForFinished();
// hasExited.acquire();
}
};

Expand Down
47 changes: 32 additions & 15 deletions ftshelpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -807,6 +810,7 @@ void FTSResultsRequest::combinedIndexSearch( BtreeIndexing::BtreeIndex & ftsInde
{
if( Utils::AtomicInt::loadAcquire( isCancelled ) )
{
Mutex::Lock _( dataMutex );
sets << tmp;
return;
}
Expand Down Expand Up @@ -839,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 )
Expand Down
6 changes: 5 additions & 1 deletion ftshelpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QRunnable>
#include <QSemaphore>
#include <QList>
#include <QtConcurrent>

#include "dictionary.hh"
#include "btreeidx.hh"
Expand Down Expand Up @@ -83,6 +84,7 @@ class FTSResultsRequest : public Dictionary::DataRequest
QAtomicInt isCancelled;

QAtomicInt results;
QFuture< void > f;

QList< FTS::FtsHeadword > * foundHeadwords;

Expand Down Expand Up @@ -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();
Expand All @@ -148,6 +151,7 @@ public:
~FTSResultsRequest()
{
isCancelled.ref();
f.waitForFinished();
if( foundHeadwords )
delete foundHeadwords;
}
Expand Down
37 changes: 25 additions & 12 deletions mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "tiff.hh"
#include "utils.hh"
#include "base/globalregex.hh"
#include <QtConcurrent>

namespace Mdx
{
Expand Down Expand Up @@ -173,17 +174,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 );
Expand Down Expand Up @@ -527,6 +534,7 @@ class MdxArticleRequest: public Dictionary::DataRequest

QAtomicInt isCancelled;
QSemaphore hasExited;
QFuture< void > f;

public:

Expand All @@ -539,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();
Expand All @@ -552,7 +561,8 @@ class MdxArticleRequest: public Dictionary::DataRequest
~MdxArticleRequest()
{
isCancelled.ref();
//hasExited.acquire();
f.waitForFinished();
// hasExited.acquire();
}
};

Expand Down Expand Up @@ -681,6 +691,7 @@ class MddResourceRequest: public Dictionary::DataRequest
wstring resourceName;
QAtomicInt isCancelled;
QSemaphore hasExited;
QFuture< void > f;

public:

Expand All @@ -689,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();
Expand All @@ -702,6 +714,7 @@ class MddResourceRequest: public Dictionary::DataRequest
~MddResourceRequest()
{
isCancelled.ref();
f.waitForFinished();
//hasExited.acquire();
}
};
Expand Down
11 changes: 9 additions & 2 deletions zim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <set>
#include <map>
#include <algorithm>
#include <QtConcurrent>

namespace Zim {

Expand Down Expand Up @@ -1248,6 +1249,7 @@ class ZimArticleRequest: public Dictionary::DataRequest

QAtomicInt isCancelled;
QSemaphore hasExited;
QFuture< void > f;

public:

Expand All @@ -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();
Expand All @@ -1269,6 +1272,7 @@ class ZimArticleRequest: public Dictionary::DataRequest
~ZimArticleRequest()
{
isCancelled.ref();
f.waitForFinished();
//hasExited.acquire();
}
};
Expand Down Expand Up @@ -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();
Expand All @@ -1438,6 +1444,7 @@ class ZimResourceRequest: public Dictionary::DataRequest
~ZimResourceRequest()
{
isCancelled.ref();
f.waitForFinished();
//hasExited.acquire();
}
};
Expand Down

0 comments on commit 59698b5

Please sign in to comment.