Guard QTime::singleShot in CWebDataServices

This commit is contained in:
Klaus Basan
2018-07-10 01:13:28 +02:00
parent ecc3f76e19
commit c8aabd675e

View File

@@ -39,6 +39,7 @@
#include <QThread> #include <QThread>
#include <QTimer> #include <QTimer>
#include <QtGlobal> #include <QtGlobal>
#include <QPointer>
using namespace BlackCore; using namespace BlackCore;
using namespace BlackCore::Db; using namespace BlackCore::Db;
@@ -1017,7 +1018,12 @@ namespace BlackCore
m_vatsimStatusReader->start(QThread::LowPriority); m_vatsimStatusReader->start(QThread::LowPriority);
// run single shot in main loop, so readInBackgroundThread is not called before initReaders completes // run single shot in main loop, so readInBackgroundThread is not called before initReaders completes
QTimer::singleShot(100, this, [this]() { m_vatsimStatusReader->readInBackgroundThread(); }); const QPointer<CWebDataServices> myself(this);
QTimer::singleShot(100, this, [ = ]()
{
if (!myself) { return; }
m_vatsimStatusReader->readInBackgroundThread();
});
} }
// ---- "normal data", triggerRead will start read, not starting directly // ---- "normal data", triggerRead will start read, not starting directly
@@ -1119,7 +1125,12 @@ namespace BlackCore
if (m_shuttingDown) { return; } if (m_shuttingDown) { return; }
if (!CThreadUtils::isCurrentThreadObjectThread(this)) if (!CThreadUtils::isCurrentThreadObjectThread(this))
{ {
QTimer::singleShot(0, this, &CWebDataServices::initDbInfoObjectReaderAndTriggerRead); const QPointer<CWebDataServices> myself(this);
QTimer::singleShot(0, this, [ = ]
{
if (!myself) { return; }
this->initDbInfoObjectReaderAndTriggerRead();
});
return; return;
} }
@@ -1142,7 +1153,12 @@ namespace BlackCore
// and trigger read // and trigger read
if (sApp->isInternetAccessible()) if (sApp->isInternetAccessible())
{ {
QTimer::singleShot(0, m_dbInfoDataReader, [this]() { m_dbInfoDataReader->read(); }); const QPointer<CWebDataServices> myself(this);
QTimer::singleShot(0, m_dbInfoDataReader, [ = ]()
{
if (!myself) { return; }
m_dbInfoDataReader->read();
});
} }
else else
{ {
@@ -1156,7 +1172,12 @@ namespace BlackCore
if (m_shuttingDown) { return; } if (m_shuttingDown) { return; }
if (!CThreadUtils::isCurrentThreadObjectThread(this)) if (!CThreadUtils::isCurrentThreadObjectThread(this))
{ {
QTimer::singleShot(0, this, &CWebDataServices::initSharedInfoObjectReaderAndTriggerRead); const QPointer<CWebDataServices> myself(this);
QTimer::singleShot(0, this, [ = ]
{
if (!myself) { return; }
this->initSharedInfoObjectReaderAndTriggerRead();
});
return; return;
} }
@@ -1179,10 +1200,10 @@ namespace BlackCore
// and trigger read // and trigger read
if (sApp->isInternetAccessible()) if (sApp->isInternetAccessible())
{ {
const QPointer<CWebDataServices> guard(this); const QPointer<CWebDataServices> myself(this);
QTimer::singleShot(0, m_sharedInfoDataReader, [ = ]() QTimer::singleShot(0, m_sharedInfoDataReader, [ = ]()
{ {
if (guard.isNull()) { return; } if (!myself) { return; }
m_sharedInfoDataReader->read(); m_sharedInfoDataReader->read();
}); });
} }
@@ -1328,8 +1349,10 @@ namespace BlackCore
{ {
if (m_shuttingDown) { return; } if (m_shuttingDown) { return; }
if (entities == CEntityFlags::NoEntity) { return; } if (entities == CEntityFlags::NoEntity) { return; }
const QPointer<CWebDataServices> myself(this);
QTimer::singleShot(delayMs, [ = ]() QTimer::singleShot(delayMs, [ = ]()
{ {
if (!myself) { return; }
this->readInBackground(entities); // deferred this->readInBackground(entities); // deferred
}); });
} }