mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #439 CWorkerBase::waitForFinished().
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "worker.h"
|
||||
#include <QWaitCondition>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -40,6 +41,19 @@ namespace BlackMisc
|
||||
QMetaObject::invokeMethod(this, "deleteLater");
|
||||
}
|
||||
|
||||
void CWorkerBase::waitForFinished()
|
||||
{
|
||||
QMutex mutex;
|
||||
QMutexLocker waitCondLock(&mutex);
|
||||
QWaitCondition waitCond;
|
||||
{
|
||||
QMutexLocker finishedLock(&m_finishedMutex);
|
||||
if (m_finished) { return; }
|
||||
then([ & ] { mutex.lock(); mutex.unlock(); waitCond.wakeAll(); });
|
||||
}
|
||||
waitCond.wait(&mutex);
|
||||
}
|
||||
|
||||
void CContinuousWorker::start(QThread::Priority priority)
|
||||
{
|
||||
if (m_name.isEmpty()) { m_name = metaObject()->className(); }
|
||||
|
||||
@@ -164,6 +164,10 @@ namespace BlackMisc
|
||||
if (m_finished) { ifFunctor(); } else { elseFunctor(); }
|
||||
}
|
||||
|
||||
//! Blocks until the task is finished.
|
||||
//! \threadsafe
|
||||
void waitForFinished();
|
||||
|
||||
signals:
|
||||
//! Emitted when the task is finished.
|
||||
void finished();
|
||||
|
||||
Reference in New Issue
Block a user