mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T105, use enabled in CContinuousWorker
* removed slots * getName
This commit is contained in:
committed by
Mathew Sutcliffe
parent
291af98770
commit
7f3643fb0e
@@ -138,25 +138,27 @@ namespace BlackMisc
|
||||
moveToThread(thread);
|
||||
connect(thread, &QThread::started, this, &CContinuousWorker::initialize);
|
||||
connect(thread, &QThread::finished, this, &CContinuousWorker::cleanup);
|
||||
connect(thread, &QThread::finished, this, &CContinuousWorker::ps_finish);
|
||||
connect(thread, &QThread::finished, this, &CContinuousWorker::finish);
|
||||
thread->start(priority);
|
||||
}
|
||||
|
||||
void CContinuousWorker::quit() noexcept
|
||||
{
|
||||
Q_ASSERT_X(!CThreadUtils::isApplicationThreadObjectThread(this), Q_FUNC_INFO, "Try to stop main thread");
|
||||
setEnabled(false);
|
||||
thread()->quit();
|
||||
}
|
||||
|
||||
void CContinuousWorker::quitAndWait() noexcept
|
||||
{
|
||||
Q_ASSERT_X(!CThreadUtils::isApplicationThreadObjectThread(this), Q_FUNC_INFO, "Try to stop main thread");
|
||||
setEnabled(false);
|
||||
auto *ownThread = thread();
|
||||
quit();
|
||||
ownThread->wait();
|
||||
}
|
||||
|
||||
void CContinuousWorker::ps_finish()
|
||||
void CContinuousWorker::finish()
|
||||
{
|
||||
setFinished();
|
||||
|
||||
|
||||
@@ -289,18 +289,28 @@ namespace BlackMisc
|
||||
//! \threadsafe Will deadlock if called by the worker thread.
|
||||
virtual void quitAndWait() noexcept final override;
|
||||
|
||||
protected slots:
|
||||
//! Enabled (running)?
|
||||
//! \threadsafe
|
||||
bool isEnabled() const { return m_enabled; }
|
||||
|
||||
//! Enabled (running)?
|
||||
//! \threadsafe
|
||||
void setEnabled(bool enabled) { m_enabled = enabled; }
|
||||
|
||||
protected:
|
||||
//! Called when the thread is started.
|
||||
virtual void initialize() {}
|
||||
|
||||
//! Called when the thread is finished.
|
||||
virtual void cleanup() {}
|
||||
|
||||
private slots:
|
||||
//! Called after cleanup().
|
||||
void ps_finish();
|
||||
//! Name of the worker
|
||||
const QString &getName() { return m_name; }
|
||||
|
||||
private:
|
||||
//! Called after cleanup().
|
||||
void finish();
|
||||
|
||||
template <typename T>
|
||||
friend class CWorkerPointer;
|
||||
|
||||
@@ -309,7 +319,8 @@ namespace BlackMisc
|
||||
using CWorkerBase::setFinished;
|
||||
|
||||
QObject *m_owner = nullptr;
|
||||
QString m_name;
|
||||
QString m_name; //!< worker's name
|
||||
std::atomic<bool> m_enabled { true }; //!< marker it is enabled
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
@@ -52,9 +52,9 @@ namespace BlackCoreTest
|
||||
|
||||
CTestReaders::~CTestReaders()
|
||||
{
|
||||
this->m_airportReader->gracefulShutdown();
|
||||
this->m_icaoReader->gracefulShutdown();
|
||||
this->m_modelReader->gracefulShutdown();
|
||||
this->m_airportReader->setEnabled(false);
|
||||
this->m_icaoReader->setEnabled(false);
|
||||
this->m_modelReader->setEnabled(false);
|
||||
}
|
||||
|
||||
void CTestReaders::readIcaoData()
|
||||
|
||||
Reference in New Issue
Block a user