mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
epwing:replace qthreadpool with qtconcurrent
This commit is contained in:
parent
f69f248c00
commit
4ffff72698
46
epwing.cc
46
epwing.cc
|
@ -862,69 +862,37 @@ sptr< Dictionary::DataRequest > EpwingDictionary::getArticle( wstring const & wo
|
||||||
|
|
||||||
//// EpwingDictionary::getResource()
|
//// EpwingDictionary::getResource()
|
||||||
|
|
||||||
class EpwingResourceRequest;
|
|
||||||
|
|
||||||
class EpwingResourceRequestRunnable: public QRunnable
|
|
||||||
{
|
|
||||||
EpwingResourceRequest & r;
|
|
||||||
QSemaphore & hasExited;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
EpwingResourceRequestRunnable( EpwingResourceRequest & r_,
|
|
||||||
QSemaphore & hasExited_ ): r( r_ ),
|
|
||||||
hasExited( hasExited_ )
|
|
||||||
{}
|
|
||||||
|
|
||||||
~EpwingResourceRequestRunnable()
|
|
||||||
{
|
|
||||||
hasExited.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void run() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class EpwingResourceRequest: public Dictionary::DataRequest
|
class EpwingResourceRequest: public Dictionary::DataRequest
|
||||||
{
|
{
|
||||||
friend class EpwingResourceRequestRunnable;
|
|
||||||
|
|
||||||
EpwingDictionary & dict;
|
EpwingDictionary & dict;
|
||||||
|
|
||||||
string resourceName;
|
string resourceName;
|
||||||
|
|
||||||
QAtomicInt isCancelled;
|
QAtomicInt isCancelled;
|
||||||
QSemaphore hasExited;
|
QFuture< void > f;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
EpwingResourceRequest( EpwingDictionary & dict_,
|
EpwingResourceRequest( EpwingDictionary & dict_, string const & resourceName_ ):
|
||||||
string const & resourceName_ ):
|
|
||||||
dict( dict_ ),
|
dict( dict_ ),
|
||||||
resourceName( resourceName_ )
|
resourceName( resourceName_ )
|
||||||
{
|
{
|
||||||
QThreadPool::globalInstance()->start(
|
f = QtConcurrent::run( [ this ]() {
|
||||||
new EpwingResourceRequestRunnable( *this, hasExited ) );
|
this->run();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(); // Run from another thread by EpwingResourceRequestRunnable
|
void run(); // Run from another thread by EpwingResourceRequestRunnable
|
||||||
|
|
||||||
void cancel() override
|
void cancel() override { isCancelled.ref(); }
|
||||||
{
|
|
||||||
isCancelled.ref();
|
|
||||||
}
|
|
||||||
|
|
||||||
~EpwingResourceRequest()
|
~EpwingResourceRequest()
|
||||||
{
|
{
|
||||||
isCancelled.ref();
|
isCancelled.ref();
|
||||||
hasExited.acquire();
|
f.waitForFinished();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void EpwingResourceRequestRunnable::run()
|
|
||||||
{
|
|
||||||
r.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EpwingResourceRequest::run()
|
void EpwingResourceRequest::run()
|
||||||
{
|
{
|
||||||
// Some runnables linger enough that they are cancelled before they start
|
// Some runnables linger enough that they are cancelled before they start
|
||||||
|
|
Loading…
Reference in a new issue