mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
On Windows, warn if a thread was terminated with its QThread still in running state.
I hope this catches if the data cache serializer is killed in the middle of a save.
This commit is contained in:
@@ -12,8 +12,46 @@
|
||||
|
||||
#include <future>
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
void CRegularThread::run()
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
m_handle = GetCurrentThread();
|
||||
QThread::run();
|
||||
m_handle = nullptr;
|
||||
#else
|
||||
QThread::run();
|
||||
#endif
|
||||
}
|
||||
|
||||
CRegularThread::~CRegularThread()
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
auto handle = m_handle.load();
|
||||
if (handle)
|
||||
{
|
||||
auto status = WaitForSingleObject(handle, 0);
|
||||
if (isRunning())
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
default:
|
||||
case WAIT_FAILED: qWarning() << "Thread" << objectName() << "unspecified error"; break;
|
||||
case WAIT_OBJECT_0: qWarning() << "Thread" << objectName() << "unsafely terminated by program shutdown"; break;
|
||||
case WAIT_TIMEOUT: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
quit();
|
||||
wait();
|
||||
}
|
||||
|
||||
CWorker *CWorker::fromTaskImpl(QObject *owner, const QString &name, int typeId, std::function<CVariant()> task)
|
||||
{
|
||||
auto *thread = new CRegularThread(owner);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <atomic>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -96,11 +97,14 @@ namespace BlackMisc
|
||||
CRegularThread(QObject *parent = nullptr) : QThread(parent) {}
|
||||
|
||||
//! Destructor
|
||||
~CRegularThread()
|
||||
{
|
||||
quit();
|
||||
wait();
|
||||
}
|
||||
~CRegularThread();
|
||||
|
||||
protected:
|
||||
//! \copydoc QThread::run
|
||||
virtual void run() override;
|
||||
|
||||
private:
|
||||
std::atomic<void *> m_handle { nullptr };
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user