mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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->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
|
||||
{
|
||||
QSet<CWorkerBase *> CWorkerBase::s_allWorkers;
|
||||
|
||||
void CRegularThread::run()
|
||||
{
|
||||
#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
|
||||
}
|
||||
|
||||
CWorkerBase::CWorkerBase()
|
||||
{
|
||||
s_allWorkers.insert(this);
|
||||
}
|
||||
|
||||
CWorkerBase::~CWorkerBase()
|
||||
{
|
||||
s_allWorkers.remove(this);
|
||||
}
|
||||
|
||||
const CLogCategoryList &CWorkerBase::getLogCategories()
|
||||
{
|
||||
static const BlackMisc::CLogCategoryList cats { CLogCategory::worker() };
|
||||
|
||||
@@ -163,6 +163,9 @@ namespace BlackMisc
|
||||
//! Convenience to call abandon() followed by waitForFinished().
|
||||
void abandonAndWait() noexcept;
|
||||
|
||||
//! All workers currently existing.
|
||||
static const QSet<CWorkerBase *> &allWorkers() { return s_allWorkers; }
|
||||
|
||||
signals:
|
||||
//! Emitted when the task is about to start.
|
||||
void aboutToStart();
|
||||
@@ -172,6 +175,12 @@ namespace BlackMisc
|
||||
void finished();
|
||||
|
||||
protected:
|
||||
//! Constructor.
|
||||
CWorkerBase();
|
||||
|
||||
//! Destructor.
|
||||
virtual ~CWorkerBase() override;
|
||||
|
||||
//! For the task to check whether it can finish early.
|
||||
//! \threadsafe
|
||||
bool isAbandoned() const;
|
||||
@@ -197,6 +206,7 @@ namespace BlackMisc
|
||||
bool m_started = false;
|
||||
bool m_finished = false;
|
||||
mutable QMutex m_finishedMutex { QMutex::Recursive };
|
||||
static QSet<CWorkerBase *> s_allWorkers;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user