diff --git a/dsl.cc b/dsl.cc index 164a42fe..b7ffbf34 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 @@ public: 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 @@ public: ~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 @@ public: 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 @@ public: ~DslResourceRequest() { isCancelled.ref(); + f.waitForFinished(); //hasExited.acquire(); } }; diff --git a/epwing.cc b/epwing.cc index 2f9ef607..bdb1d28b 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 @@ public: 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 @@ public: ~EpwingArticleRequest() { isCancelled.ref(); - hasExited.acquire(); + f.waitForFinished(); + // hasExited.acquire(); } }; diff --git a/ftshelpers.hh b/ftshelpers.hh index 5a5ac6ea..cf02a06c 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 448b7a1f..fb1df58f 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 @@ public: 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 @@ public: ~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 @@ public: 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 @@ public: ~MddResourceRequest() { isCancelled.ref(); + f.waitForFinished(); //hasExited.acquire(); } }; diff --git a/zim.cc b/zim.cc index 6dc8a9b1..de827bfc 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 @@ public: 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 @@ public: ~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 @@ public: ~ZimResourceRequest() { isCancelled.ref(); + f.waitForFinished(); //hasExited.acquire(); } };