mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 12:35:43 +08:00
[Worker] Stop timer in correct thread
This commit is contained in:
committed by
Mat Sutcliffe
parent
5718f95819
commit
1da66ce6e9
@@ -107,7 +107,7 @@ namespace BlackMisc
|
|||||||
void CBackgroundValidation::beforeQuit() noexcept
|
void CBackgroundValidation::beforeQuit() noexcept
|
||||||
{
|
{
|
||||||
m_wasStopped = true; // stop in utility functions
|
m_wasStopped = true; // stop in utility functions
|
||||||
m_updateTimer.stop();
|
this->stopUpdateTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBackgroundValidation::doWork()
|
void CBackgroundValidation::doWork()
|
||||||
|
|||||||
@@ -237,6 +237,27 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CContinuousWorker::stopUpdateTimer()
|
||||||
|
{
|
||||||
|
if (!m_updateTimer.isActive()) { return; }
|
||||||
|
|
||||||
|
// avoid "Timers cannot be stopped from another thread"
|
||||||
|
if (CThreadUtils::isCurrentThreadObjectThread(&m_updateTimer))
|
||||||
|
{
|
||||||
|
m_updateTimer.stop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QPointer<CContinuousWorker> myself(this);
|
||||||
|
QTimer::singleShot(0, &m_updateTimer, [ = ]
|
||||||
|
{
|
||||||
|
// stop timer in timer thread
|
||||||
|
if (!myself) { return; }
|
||||||
|
m_updateTimer.stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CContinuousWorker::finish()
|
void CContinuousWorker::finish()
|
||||||
{
|
{
|
||||||
this->setFinished();
|
this->setFinished();
|
||||||
|
|||||||
@@ -334,6 +334,9 @@ namespace BlackMisc
|
|||||||
//! Wait time for quitAndWait, 0 means not waiting
|
//! Wait time for quitAndWait, 0 means not waiting
|
||||||
virtual unsigned long waitTimeoutMs() const { return 15 * 1000; }
|
virtual unsigned long waitTimeoutMs() const { return 15 * 1000; }
|
||||||
|
|
||||||
|
//! Safely stop update time
|
||||||
|
void stopUpdateTimer();
|
||||||
|
|
||||||
QTimer m_updateTimer { this }; //!< timer which can be used by implementing classes
|
QTimer m_updateTimer { this }; //!< timer which can be used by implementing classes
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -345,7 +348,7 @@ namespace BlackMisc
|
|||||||
using CWorkerBase::setFinished;
|
using CWorkerBase::setFinished;
|
||||||
|
|
||||||
QObject *m_owner = nullptr; //!< owner, parent of the QThread
|
QObject *m_owner = nullptr; //!< owner, parent of the QThread
|
||||||
QString m_name; //!< worker's name
|
QString m_name; //!< worker's name
|
||||||
std::atomic<bool> m_enabled { true }; //!< marker it is enabled
|
std::atomic<bool> m_enabled { true }; //!< marker it is enabled
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user