T66 Tidying up CBackgroundDataUpdater startup and shutdown

by overriding the CContinuousWorker virtual methods that exist for this purpose.
This commit is contained in:
Mathew Sutcliffe
2017-05-07 03:18:38 +01:00
parent 41ff563e19
commit 98e67860bc
2 changed files with 17 additions and 6 deletions

View File

@@ -37,9 +37,20 @@ namespace BlackCore
CContinuousWorker(owner, "Background data updater") CContinuousWorker(owner, "Background data updater")
{ {
connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork); connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork);
}
void CBackgroundDataUpdater::initialize()
{
m_updateTimer.start(60 * 1000); m_updateTimer.start(60 * 1000);
} }
void CBackgroundDataUpdater::cleanup()
{
m_updateTimer.stop();
m_shutdown = true;
m_enabled = false;
}
CBackgroundDataUpdater::~CBackgroundDataUpdater() CBackgroundDataUpdater::~CBackgroundDataUpdater()
{ {
gracefulShutdown(); gracefulShutdown();
@@ -60,18 +71,12 @@ namespace BlackCore
void CBackgroundDataUpdater::gracefulShutdown() void CBackgroundDataUpdater::gracefulShutdown()
{ {
if (m_shutdown) { return; }
m_shutdown = true; m_shutdown = true;
m_enabled = false; m_enabled = false;
if (!CThreadUtils::isCurrentThreadObjectThread(this)) if (!CThreadUtils::isCurrentThreadObjectThread(this))
{ {
this->abandonAndWait(); this->abandonAndWait();
} }
else
{
// timer needs to be stopped in its own thread
m_updateTimer.stop();
}
} }
void CBackgroundDataUpdater::startUpdating(int updateTimeSecs) void CBackgroundDataUpdater::startUpdating(int updateTimeSecs)

View File

@@ -38,6 +38,12 @@ namespace BlackCore
//! Destructor //! Destructor
virtual ~CBackgroundDataUpdater(); virtual ~CBackgroundDataUpdater();
//! \copydoc BlackMisc::CContinuousWorker::initialize
virtual void initialize() override;
//! \copydoc BlackMisc::CContinuousWorker::cleanup
virtual void cleanup() override;
//! Is shutting down? //! Is shutting down?
//! \threadsafe //! \threadsafe
bool isShuttingDown() const; bool isShuttingDown() const;