mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
refs #476 CThreadedReader::gracefulShutdown using the worker abandon feature, removed m_shutdown.
This commit is contained in:
@@ -26,7 +26,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CDatabaseReader::readInBackgroundThread(CEntityFlags::Entity entities)
|
void CDatabaseReader::readInBackgroundThread(CEntityFlags::Entity entities)
|
||||||
{
|
{
|
||||||
if (isFinishedOrShutdown()) { return; }
|
if (isAbandoned()) { return; }
|
||||||
this->m_watchdogTimer.stop();
|
this->m_watchdogTimer.stop();
|
||||||
bool s = QMetaObject::invokeMethod(this, "ps_read", Q_ARG(BlackMisc::Network::CEntityFlags::Entity, entities));
|
bool s = QMetaObject::invokeMethod(this, "ps_read", Q_ARG(BlackMisc::Network::CEntityFlags::Entity, entities));
|
||||||
Q_ASSERT_X(s, Q_FUNC_INFO, "Invoke failed");
|
Q_ASSERT_X(s, Q_FUNC_INFO, "Invoke failed");
|
||||||
@@ -37,7 +37,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
this->threadAssertCheck();
|
this->threadAssertCheck();
|
||||||
JsonDatastoreResponse datastoreResponse;
|
JsonDatastoreResponse datastoreResponse;
|
||||||
if (this->isFinishedOrShutdown())
|
if (this->isAbandoned())
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("Terminated data parsing process"); // for users
|
CLogMessage(this).info("Terminated data parsing process"); // for users
|
||||||
nwReply->abort();
|
nwReply->abort();
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ namespace BlackCore
|
|||||||
QString urlString(url.toString());
|
QString urlString(url.toString());
|
||||||
QString replyMessage(nwReply->errorString());
|
QString replyMessage(nwReply->errorString());
|
||||||
|
|
||||||
if (this->isFinishedOrShutdown())
|
if (this->isAbandoned())
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("Terminated loading bootstrap files");
|
CLogMessage(this).info("Terminated loading bootstrap files");
|
||||||
nwReply->abort();
|
nwReply->abort();
|
||||||
@@ -232,7 +232,7 @@ namespace BlackCore
|
|||||||
QString urlString(url.toString());
|
QString urlString(url.toString());
|
||||||
QString replyMessage(nwReply->errorString());
|
QString replyMessage(nwReply->errorString());
|
||||||
|
|
||||||
if (this->isFinishedOrShutdown())
|
if (this->isAbandoned())
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("Terminated loading of update info");
|
CLogMessage(this).info("Terminated loading of update info");
|
||||||
nwReply->abort();
|
nwReply->abort();
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace BlackCore
|
|||||||
this->threadAssertCheck();
|
this->threadAssertCheck();
|
||||||
|
|
||||||
// Worker thread, make sure to write no members here!
|
// Worker thread, make sure to write no members here!
|
||||||
if (this->isFinishedOrShutdown())
|
if (this->isAbandoned())
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||||
CLogMessage(this).info("terminated booking parsing process"); // for users
|
CLogMessage(this).info("terminated booking parsing process"); // for users
|
||||||
@@ -93,7 +93,7 @@ namespace BlackCore
|
|||||||
CAtcStationList bookedStations;
|
CAtcStationList bookedStations;
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
if (this->isFinishedOrShutdown())
|
if (this->isAbandoned())
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||||
CLogMessage(this).info("Terminated booking parsing process"); // for users
|
CLogMessage(this).info("Terminated booking parsing process"); // for users
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ namespace BlackCore
|
|||||||
this->threadAssertCheck();
|
this->threadAssertCheck();
|
||||||
|
|
||||||
// Worker thread, make sure to write only synced here!
|
// Worker thread, make sure to write only synced here!
|
||||||
if (this->isFinishedOrShutdown())
|
if (this->isAbandoned())
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||||
CLogMessage(this).info("Terminated VATSIM file parsing process"); // for users
|
CLogMessage(this).info("Terminated VATSIM file parsing process"); // for users
|
||||||
@@ -201,7 +201,7 @@ namespace BlackCore
|
|||||||
Section section = SectionNone;
|
Section section = SectionNone;
|
||||||
for (const QString &cl : lines)
|
for (const QString &cl : lines)
|
||||||
{
|
{
|
||||||
if (this->isFinishedOrShutdown())
|
if (this->isAbandoned())
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||||
CLogMessage(this).info("Terminated booking parsing process"); // for users
|
CLogMessage(this).info("Terminated booking parsing process"); // for users
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace BlackCore
|
|||||||
this->threadAssertCheck();
|
this->threadAssertCheck();
|
||||||
|
|
||||||
// Worker thread, make sure to write thread safe!
|
// Worker thread, make sure to write thread safe!
|
||||||
if (this->isFinishedOrShutdown())
|
if (this->isAbandoned())
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||||
CLogMessage(this).info("terminated METAR decoding process"); // for users
|
CLogMessage(this).info("terminated METAR decoding process"); // for users
|
||||||
@@ -94,7 +94,7 @@ namespace BlackCore
|
|||||||
QTextStream lineReader(&metarData);
|
QTextStream lineReader(&metarData);
|
||||||
while (!lineReader.atEnd())
|
while (!lineReader.atEnd())
|
||||||
{
|
{
|
||||||
if (this->isFinishedOrShutdown()) { return; }
|
if (this->isAbandoned()) { return; }
|
||||||
QString line = lineReader.readLine();
|
QString line = lineReader.readLine();
|
||||||
CMetar metar = m_metarDecoder.decode(line);
|
CMetar metar = m_metarDecoder.decode(line);
|
||||||
if (metar != CMetar())
|
if (metar != CMetar())
|
||||||
|
|||||||
@@ -36,11 +36,6 @@ namespace BlackMisc
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CThreadedReader::isFinishedOrShutdown() const
|
|
||||||
{
|
|
||||||
return m_shutdown || isFinished();
|
|
||||||
}
|
|
||||||
|
|
||||||
QDateTime CThreadedReader::getUpdateTimestamp() const
|
QDateTime CThreadedReader::getUpdateTimestamp() const
|
||||||
{
|
{
|
||||||
QReadLocker lock(&this->m_lock);
|
QReadLocker lock(&this->m_lock);
|
||||||
@@ -53,14 +48,6 @@ namespace BlackMisc
|
|||||||
this->m_updateTimestamp = updateTimestamp;
|
this->m_updateTimestamp = updateTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadedReader::requestStop()
|
|
||||||
{
|
|
||||||
if (m_updateTimer)
|
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod(m_updateTimer, "stop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CThreadedReader::requestReload()
|
void CThreadedReader::requestReload()
|
||||||
{
|
{
|
||||||
// default implementation, subclasses shall override as required
|
// default implementation, subclasses shall override as required
|
||||||
@@ -69,15 +56,11 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CThreadedReader::gracefulShutdown()
|
void CThreadedReader::gracefulShutdown()
|
||||||
{
|
{
|
||||||
if (this->m_shutdown) { return; }
|
this->abandonAndWait();
|
||||||
this->m_shutdown = true;
|
|
||||||
this->requestStop();
|
|
||||||
this->quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CThreadedReader::~CThreadedReader()
|
CThreadedReader::~CThreadedReader()
|
||||||
{
|
{
|
||||||
this->m_shutdown = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadedReader::setInterval(int updatePeriodMs)
|
void CThreadedReader::setInterval(int updatePeriodMs)
|
||||||
|
|||||||
@@ -38,10 +38,6 @@ namespace BlackMisc
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
void setUpdateTimestamp(const QDateTime &updateTimestamp);
|
void setUpdateTimestamp(const QDateTime &updateTimestamp);
|
||||||
|
|
||||||
//! Request to stop
|
|
||||||
//! \threadsafe
|
|
||||||
void requestStop();
|
|
||||||
|
|
||||||
//! Request new reading
|
//! Request new reading
|
||||||
//! \note override as required, default is to call initialize()
|
//! \note override as required, default is to call initialize()
|
||||||
virtual void requestReload();
|
virtual void requestReload();
|
||||||
@@ -65,7 +61,6 @@ namespace BlackMisc
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTimer *m_updateTimer = nullptr; //!< update timer
|
QTimer *m_updateTimer = nullptr; //!< update timer
|
||||||
std::atomic<bool> m_shutdown { false }; //!< in shutdown process
|
|
||||||
mutable QReadWriteLock m_lock {QReadWriteLock::Recursive}; //!< lock which can be used from the derived classes
|
mutable QReadWriteLock m_lock {QReadWriteLock::Recursive}; //!< lock which can be used from the derived classes
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
@@ -74,9 +69,6 @@ namespace BlackMisc
|
|||||||
//! When was reply last modified, -1 if N/A
|
//! When was reply last modified, -1 if N/A
|
||||||
qint64 lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const;
|
qint64 lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const;
|
||||||
|
|
||||||
//! Shutdown in progress or finished
|
|
||||||
bool isFinishedOrShutdown() const;
|
|
||||||
|
|
||||||
//! Make sure everthing runs correctly in own thread
|
//! Make sure everthing runs correctly in own thread
|
||||||
void threadAssertCheck() const;
|
void threadAssertCheck() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user