From 7d106acdeedf38bc5ab25ae0c3fe845e1f84432e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 4 Apr 2018 00:04:04 +0200 Subject: [PATCH] DB reader, doWorkCheck before writing cache. In case shutdown takes place in-between. --- src/blackcore/db/airportdatareader.cpp | 1 + src/blackcore/db/icaodatareader.cpp | 3 +++ src/blackcore/db/modeldatareader.cpp | 3 +++ src/blackcore/threadedreader.cpp | 6 +++--- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/blackcore/db/airportdatareader.cpp b/src/blackcore/db/airportdatareader.cpp index e189aa287..a82a6442e 100644 --- a/src/blackcore/db/airportdatareader.cpp +++ b/src/blackcore/db/airportdatareader.cpp @@ -215,6 +215,7 @@ namespace BlackCore Q_FUNC_INFO); } + if (!this->doWorkCheck()) { return; } const int size = airports.size(); qint64 latestTimestamp = airports.latestTimestampMsecsSinceEpoch(); if (size > 0 && latestTimestamp < 0) diff --git a/src/blackcore/db/icaodatareader.cpp b/src/blackcore/db/icaodatareader.cpp index abb087c23..c3574de14 100644 --- a/src/blackcore/db/icaodatareader.cpp +++ b/src/blackcore/db/icaodatareader.cpp @@ -292,6 +292,7 @@ namespace BlackCore Q_FUNC_INFO); } + if (!this->doWorkCheck()) { return; } const int n = codes.size(); qint64 latestTimestamp = codes.latestTimestampMsecsSinceEpoch(); // ignores duplicates if (n > 0 && latestTimestamp < 0) @@ -342,6 +343,7 @@ namespace BlackCore Q_FUNC_INFO); } + if (!this->doWorkCheck()) { return; } const int n = codes.size(); qint64 latestTimestamp = codes.latestTimestampMsecsSinceEpoch(); if (n > 0 && latestTimestamp < 0) @@ -382,6 +384,7 @@ namespace BlackCore countries = CCountryList::fromDatabaseJson(res); } + if (!this->doWorkCheck()) { return; } const int n = countries.size(); qint64 latestTimestamp = countries.latestTimestampMsecsSinceEpoch(); if (n > 0 && latestTimestamp < 0) diff --git a/src/blackcore/db/modeldatareader.cpp b/src/blackcore/db/modeldatareader.cpp index dbc4b5098..dc5d3a20a 100644 --- a/src/blackcore/db/modeldatareader.cpp +++ b/src/blackcore/db/modeldatareader.cpp @@ -301,6 +301,7 @@ namespace BlackCore liveries = CLiveryList::fromDatabaseJson(res); } + if (!this->doWorkCheck()) { return; } const int n = liveries.size(); qint64 latestTimestamp = liveries.latestTimestampMsecsSinceEpoch(); if (n > 0 && latestTimestamp < 0) @@ -343,6 +344,7 @@ namespace BlackCore distributors = CDistributorList::fromDatabaseJson(res); } + if (!this->doWorkCheck()) { return; } const int n = distributors.size(); qint64 latestTimestamp = distributors.latestTimestampMsecsSinceEpoch(); if (n > 0 && latestTimestamp < 0) @@ -386,6 +388,7 @@ namespace BlackCore } // synchronized update + if (!this->doWorkCheck()) { return; } const int n = models.size(); qint64 latestTimestamp = models.latestTimestampMsecsSinceEpoch(); if (n > 0 && latestTimestamp < 0) diff --git a/src/blackcore/threadedreader.cpp b/src/blackcore/threadedreader.cpp index cc62ae1d8..43e351768 100644 --- a/src/blackcore/threadedreader.cpp +++ b/src/blackcore/threadedreader.cpp @@ -157,7 +157,7 @@ namespace BlackCore void CThreadedReader::doWork() { if (!doWorkCheck()) { return; } - doWorkImpl(); + this->doWorkImpl(); Q_ASSERT(m_periodicTime > 0); m_updateTimer.start(m_periodicTime); // restart } @@ -165,8 +165,8 @@ namespace BlackCore bool CThreadedReader::doWorkCheck() const { // sApp->hasWebDataServices() cannot be used, as some readers are already used during init phase - if (!isEnabled()) { return false; } - if (isAbandoned()) { return false; } + if (!this->isEnabled()) { return false; } + if (this->isAbandoned()) { return false; } if (!m_unitTest && (!sApp || sApp->isShuttingDown())) { return false; } return true; }