mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
refs #476, improvements on gracefulShutdown
* gracefulShutdown in metar reader and other readers * made m_shutdown thread safe * Demoted log level for reader * helper function finished or shutdown
This commit is contained in:
committed by
Mathew Sutcliffe
parent
54448fd2b2
commit
4d3d9fa6be
@@ -37,7 +37,7 @@ namespace BlackCore
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
JsonDatastoreResponse datastoreResponse;
|
||||
if (m_shutdown || this->isFinished())
|
||||
if (this->isFinishedOrShutdown())
|
||||
{
|
||||
CLogMessage(this).info("Terminated data parsing process"); // for users
|
||||
nwReply->abort();
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace BlackCore
|
||||
QString replyMessage(nwReply->errorString());
|
||||
|
||||
this->threadAssertCheck();
|
||||
if (this->isFinished())
|
||||
if (this->isFinishedOrShutdown())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("Terminated loading bootstrap files");
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace BlackCore
|
||||
this->threadAssertCheck();
|
||||
|
||||
// Worker thread, make sure to write no members here!
|
||||
if (this->isFinished())
|
||||
if (this->isFinishedOrShutdown())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("terminated booking parsing process"); // for users
|
||||
@@ -93,7 +93,7 @@ namespace BlackCore
|
||||
CAtcStationList bookedStations;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (this->isFinished())
|
||||
if (this->isFinishedOrShutdown())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("Terminated booking parsing process"); // for users
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace BlackCore
|
||||
this->threadAssertCheck();
|
||||
|
||||
// Worker thread, make sure to write only synced here!
|
||||
if (this->isFinished())
|
||||
if (this->isFinishedOrShutdown())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("Terminated VATSIM file parsing process"); // for users
|
||||
@@ -200,9 +200,9 @@ namespace BlackCore
|
||||
|
||||
QStringList clientSectionAttributes;
|
||||
Section section = SectionNone;
|
||||
foreach(QString currentLine, lines)
|
||||
for (const QString &cl : lines)
|
||||
{
|
||||
if (this->isFinished())
|
||||
if (this->isFinishedOrShutdown())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("Terminated booking parsing process"); // for users
|
||||
@@ -210,7 +210,7 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
// parse lines
|
||||
currentLine = currentLine.trimmed();
|
||||
QString currentLine(cl.trimmed());
|
||||
if (currentLine.isEmpty()) continue;
|
||||
if (currentLine.startsWith(";"))
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace BlackCore
|
||||
this->threadAssertCheck();
|
||||
|
||||
// Worker thread, make sure to write thread safe!
|
||||
if (this->isFinished())
|
||||
if (this->isFinishedOrShutdown())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("terminated METAR decoding process"); // for users
|
||||
@@ -94,6 +94,7 @@ namespace BlackCore
|
||||
QTextStream lineReader(&metarData);
|
||||
while (!lineReader.atEnd())
|
||||
{
|
||||
if (this->isFinishedOrShutdown()) { return; }
|
||||
QString line = lineReader.readLine();
|
||||
CMetar metar = m_metarDecoder.decode(line);
|
||||
if (metar != CMetar())
|
||||
@@ -117,7 +118,8 @@ namespace BlackCore
|
||||
Q_UNUSED(invalidMetars);
|
||||
if (invalidLineCount > 0)
|
||||
{
|
||||
CLogMessage(this).warning("Reading METARs failed for %1 entries") << invalidLineCount;
|
||||
// Regular issue, log it, but do not show to user
|
||||
CLogMessage(this).debug() << "Reading METARs failed for entries" << invalidLineCount;
|
||||
}
|
||||
emit metarsRead(metars);
|
||||
emit dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFinished, metars.size());
|
||||
|
||||
@@ -374,9 +374,10 @@ namespace BlackCore
|
||||
this->disconnect(); // all signals
|
||||
if (this->m_vatsimBookingReader) { this->m_vatsimBookingReader->gracefulShutdown(); }
|
||||
if (this->m_vatsimDataFileReader) { this->m_vatsimDataFileReader->gracefulShutdown(); }
|
||||
if (this->m_modelDataReader) { this->m_modelDataReader->gracefulShutdown(); }
|
||||
if (this->m_icaoDataReader) { this->m_icaoDataReader->gracefulShutdown(); }
|
||||
if (this->m_databaseWriter) { this->m_databaseWriter->gracefulShutdown(); }
|
||||
if (this->m_vatsimMetarReader) { this->m_vatsimMetarReader->gracefulShutdown(); }
|
||||
if (this->m_modelDataReader) { this->m_modelDataReader->gracefulShutdown(); }
|
||||
if (this->m_icaoDataReader) { this->m_icaoDataReader->gracefulShutdown(); }
|
||||
if (this->m_databaseWriter) { this->m_databaseWriter->gracefulShutdown(); }
|
||||
}
|
||||
|
||||
const CLogCategoryList &CWebDataServices::getLogCategories()
|
||||
|
||||
@@ -19,6 +19,11 @@ namespace BlackMisc
|
||||
m_updateTimer(new QTimer(this))
|
||||
{ }
|
||||
|
||||
bool CThreadedReader::isFinishedOrShutdown() const
|
||||
{
|
||||
return m_shutdown || isFinished();
|
||||
}
|
||||
|
||||
QDateTime CThreadedReader::getUpdateTimestamp() const
|
||||
{
|
||||
QReadLocker lock(&this->m_lock);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <QTimer>
|
||||
#include <QNetworkReply>
|
||||
#include <QCoreApplication>
|
||||
#include <atomic>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -57,16 +58,20 @@ namespace BlackMisc
|
||||
int interval() const;
|
||||
|
||||
//! Graceful shutdown
|
||||
//! \threadsafe
|
||||
void gracefulShutdown();
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CThreadedReader(QObject *owner, const QString &name);
|
||||
|
||||
QTimer *m_updateTimer = nullptr; //!< update timer
|
||||
bool m_shutdown = false; //!< in shutdown process
|
||||
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
|
||||
|
||||
//! Shutdown in progress or finished
|
||||
bool isFinishedOrShutdown() const;
|
||||
|
||||
//! Make sure everthing runs correctly in own thread
|
||||
void threadAssertCheck() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user