mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
refs #833, use isShuttingDown in readers
(a bit stricter than this->isAbandoned)
This commit is contained in:
@@ -156,7 +156,7 @@ namespace BlackCore
|
||||
void CAirportDataReader::ps_read(CEntityFlags::Entity entity, CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan)
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
|
||||
if (entity.testFlag(CEntityFlags::AirportEntity))
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace BlackCore
|
||||
|
||||
void CDatabaseReader::readInBackgroundThread(CEntityFlags::Entity entities, const QDateTime &newerThan)
|
||||
{
|
||||
if (isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
|
||||
// we accept cached cached data
|
||||
Q_ASSERT_X(!entities.testFlag(CEntityFlags::InfoObjectEntity), Q_FUNC_INFO, "Read info objects directly");
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace BlackCore
|
||||
void CIcaoDataReader::ps_read(BlackMisc::Network::CEntityFlags::Entity entities, BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan)
|
||||
{
|
||||
this->threadAssertCheck(); // runs in background thread
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
|
||||
CEntityFlags::Entity entitiesTriggered = CEntityFlags::NoEntity;
|
||||
if (entities.testFlag(CEntityFlags::AircraftIcaoEntity))
|
||||
@@ -221,7 +221,7 @@ namespace BlackCore
|
||||
// wrap pointer, make sure any exit cleans up reply
|
||||
// required to use delete later as object is created in a different thread
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
|
||||
const QString urlString(nwReply->url().toString());
|
||||
CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
||||
@@ -251,7 +251,7 @@ namespace BlackCore
|
||||
void CIcaoDataReader::ps_parseAirlineIcaoData(QNetworkReply *nwReplyPtr)
|
||||
{
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
|
||||
QString urlString(nwReply->url().toString());
|
||||
CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace BlackCore
|
||||
// wrap pointer, make sure any exit cleans up reply
|
||||
// required to use delete later as object is created in a different thread
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
|
||||
QString urlString(nwReply->url().toString());
|
||||
CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace BlackCore
|
||||
void CModelDataReader::ps_read(CEntityFlags::Entity entity, CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan)
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
|
||||
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
|
||||
if (entity.testFlag(CEntityFlags::LiveryEntity))
|
||||
@@ -252,7 +252,7 @@ namespace BlackCore
|
||||
// wrap pointer, make sure any exit cleans up reply
|
||||
// required to use delete later as object is created in a different thread
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
QString urlString(nwReply->url().toString());
|
||||
CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
||||
if (res.hasErrorMessage())
|
||||
@@ -295,7 +295,7 @@ namespace BlackCore
|
||||
// wrap pointer, make sure any exit cleans up reply
|
||||
// required to use delete later as object is created in a different thread
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
const QString urlString(nwReply->url().toString());
|
||||
CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
||||
if (res.hasErrorMessage())
|
||||
@@ -337,8 +337,8 @@ namespace BlackCore
|
||||
// wrap pointer, make sure any exit cleans up reply
|
||||
// required to use delete later as object is created in a different thread
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||
if (this->isAbandoned()) { return; }
|
||||
QString urlString(nwReply->url().toString());
|
||||
if (this->isShuttingDown()) { return; }
|
||||
const QString urlString(nwReply->url().toString());
|
||||
CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
||||
if (res.hasErrorMessage())
|
||||
{
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
#include "blackcore/threadedreader.h"
|
||||
#include "blackcore/application.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
#include "blackmisc/threadutils.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -77,6 +78,7 @@ namespace BlackCore
|
||||
void CThreadedReader::gracefulShutdown()
|
||||
{
|
||||
// if not in main thread stop, otherwise it makes no sense to abandon
|
||||
this->m_shutdown = true;
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
this->abandonAndWait();
|
||||
@@ -86,7 +88,7 @@ namespace BlackCore
|
||||
void CThreadedReader::startReader()
|
||||
{
|
||||
Q_ASSERT(m_initialTime > 0);
|
||||
QTimer::singleShot(m_initialTime, this, [=] { this->doWork(); });
|
||||
QTimer::singleShot(m_initialTime, this, [ = ] { this->doWork(); });
|
||||
}
|
||||
|
||||
void CThreadedReader::pauseReader()
|
||||
@@ -94,6 +96,14 @@ namespace BlackCore
|
||||
QTimer::singleShot(0, m_updateTimer, &QTimer::stop);
|
||||
}
|
||||
|
||||
bool CThreadedReader::isShuttingDown() const
|
||||
{
|
||||
if (this->m_shutdown) { return true; }
|
||||
if (this->isAbandoned()) { return true; }
|
||||
if (!sApp) { return true; } // sApp object is gone, whole system shutdown
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CThreadedReader::didContentChange(const QString &content, int startPosition)
|
||||
{
|
||||
uint oldHash = 0;
|
||||
|
||||
@@ -71,7 +71,10 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
void pauseReader();
|
||||
|
||||
public slots:
|
||||
//! Is shutting down?
|
||||
//! \threadsafe
|
||||
bool isShuttingDown() const;
|
||||
|
||||
//! Graceful shutdown
|
||||
//! \threadsafe
|
||||
void gracefulShutdown();
|
||||
@@ -106,6 +109,7 @@ namespace BlackCore
|
||||
QDateTime m_updateTimestamp; //!< when file/resource was read
|
||||
uint m_contentHash = 0; //!< has of the content given
|
||||
std::atomic<bool> m_markedAsFailed { false }; //!< marker if reading failed
|
||||
std::atomic<bool> m_shutdown { false }; //!< marker it is shutting down
|
||||
QTimer *m_updateTimer = nullptr;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user