mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
Track worker construction and destruction
Added debug log messages in case a worker still exists when the `qApp` is destroyed. This would mean that a `quitAndWait` is missing or is being skipped somewhere.
This commit is contained in:
@@ -173,6 +173,14 @@ namespace BlackCore
|
|||||||
m_inputManager = new CInputManager(this);
|
m_inputManager = new CInputManager(this);
|
||||||
m_inputManager->createDevices();
|
m_inputManager->createDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(this, &QObject::destroyed, [cat = CLogCategoryList(this)]
|
||||||
|
{
|
||||||
|
for (CWorkerBase *worker : CWorkerBase::allWorkers())
|
||||||
|
{
|
||||||
|
CLogMessage(cat).debug(u"Worker named '%1' still exists after application destroyed") << worker->objectName();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
QSet<CWorkerBase *> CWorkerBase::s_allWorkers;
|
||||||
|
|
||||||
void CRegularThread::run()
|
void CRegularThread::run()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
@@ -105,6 +107,16 @@ namespace BlackMisc
|
|||||||
// must not access the worker beyond this point, as it now lives in the owner's thread and could be deleted at any moment
|
// must not access the worker beyond this point, as it now lives in the owner's thread and could be deleted at any moment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CWorkerBase::CWorkerBase()
|
||||||
|
{
|
||||||
|
s_allWorkers.insert(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
CWorkerBase::~CWorkerBase()
|
||||||
|
{
|
||||||
|
s_allWorkers.remove(this);
|
||||||
|
}
|
||||||
|
|
||||||
const CLogCategoryList &CWorkerBase::getLogCategories()
|
const CLogCategoryList &CWorkerBase::getLogCategories()
|
||||||
{
|
{
|
||||||
static const BlackMisc::CLogCategoryList cats { CLogCategory::worker() };
|
static const BlackMisc::CLogCategoryList cats { CLogCategory::worker() };
|
||||||
|
|||||||
@@ -163,6 +163,9 @@ namespace BlackMisc
|
|||||||
//! Convenience to call abandon() followed by waitForFinished().
|
//! Convenience to call abandon() followed by waitForFinished().
|
||||||
void abandonAndWait() noexcept;
|
void abandonAndWait() noexcept;
|
||||||
|
|
||||||
|
//! All workers currently existing.
|
||||||
|
static const QSet<CWorkerBase *> &allWorkers() { return s_allWorkers; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Emitted when the task is about to start.
|
//! Emitted when the task is about to start.
|
||||||
void aboutToStart();
|
void aboutToStart();
|
||||||
@@ -172,6 +175,12 @@ namespace BlackMisc
|
|||||||
void finished();
|
void finished();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
//! Constructor.
|
||||||
|
CWorkerBase();
|
||||||
|
|
||||||
|
//! Destructor.
|
||||||
|
virtual ~CWorkerBase() override;
|
||||||
|
|
||||||
//! For the task to check whether it can finish early.
|
//! For the task to check whether it can finish early.
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
bool isAbandoned() const;
|
bool isAbandoned() const;
|
||||||
@@ -197,6 +206,7 @@ namespace BlackMisc
|
|||||||
bool m_started = false;
|
bool m_started = false;
|
||||||
bool m_finished = false;
|
bool m_finished = false;
|
||||||
mutable QMutex m_finishedMutex { QMutex::Recursive };
|
mutable QMutex m_finishedMutex { QMutex::Recursive };
|
||||||
|
static QSet<CWorkerBase *> s_allWorkers;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Reference in New Issue
Block a user