mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 05:45:35 +08:00
refs #439 CWorkerBase::waitForFinished().
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "worker.h"
|
#include "worker.h"
|
||||||
|
#include <QWaitCondition>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -40,6 +41,19 @@ namespace BlackMisc
|
|||||||
QMetaObject::invokeMethod(this, "deleteLater");
|
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)
|
void CContinuousWorker::start(QThread::Priority priority)
|
||||||
{
|
{
|
||||||
if (m_name.isEmpty()) { m_name = metaObject()->className(); }
|
if (m_name.isEmpty()) { m_name = metaObject()->className(); }
|
||||||
|
|||||||
@@ -164,6 +164,10 @@ namespace BlackMisc
|
|||||||
if (m_finished) { ifFunctor(); } else { elseFunctor(); }
|
if (m_finished) { ifFunctor(); } else { elseFunctor(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Blocks until the task is finished.
|
||||||
|
//! \threadsafe
|
||||||
|
void waitForFinished();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Emitted when the task is finished.
|
//! Emitted when the task is finished.
|
||||||
void finished();
|
void finished();
|
||||||
|
|||||||
Reference in New Issue
Block a user