mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-16 21:51:17 +00:00
Ensure all polling threads are dead before destroying hosts, even ones that have been detached by stopPollingAsync()
This commit is contained in:
@@ -51,6 +51,79 @@ private:
|
||||
QMdnsEngine::Resolver m_Resolver;
|
||||
};
|
||||
|
||||
class ComputerPollingEntry
|
||||
{
|
||||
public:
|
||||
ComputerPollingEntry()
|
||||
: m_ActiveThread(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual ~ComputerPollingEntry()
|
||||
{
|
||||
interrupt();
|
||||
|
||||
// interrupt() should have taken care of this
|
||||
Q_ASSERT(m_ActiveThread == nullptr);
|
||||
|
||||
for (QThread* thread : m_InactiveList) {
|
||||
thread->wait();
|
||||
delete thread;
|
||||
}
|
||||
}
|
||||
|
||||
bool isActive()
|
||||
{
|
||||
cleanInactiveList();
|
||||
|
||||
return m_ActiveThread != nullptr;
|
||||
}
|
||||
|
||||
void setActiveThread(QThread* thread)
|
||||
{
|
||||
cleanInactiveList();
|
||||
|
||||
Q_ASSERT(!isActive());
|
||||
m_ActiveThread = thread;
|
||||
}
|
||||
|
||||
void interrupt()
|
||||
{
|
||||
cleanInactiveList();
|
||||
|
||||
if (m_ActiveThread != nullptr) {
|
||||
// Interrupt the active thread
|
||||
m_ActiveThread->requestInterruption();
|
||||
|
||||
// Place it on the inactive list awaiting death
|
||||
m_InactiveList.append(m_ActiveThread);
|
||||
|
||||
m_ActiveThread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void cleanInactiveList()
|
||||
{
|
||||
QMutableListIterator<QThread*> i(m_InactiveList);
|
||||
|
||||
// Reap any threads that have finished
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
|
||||
QThread* thread = i.value();
|
||||
if (thread->isFinished()) {
|
||||
delete thread;
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QThread* m_ActiveThread;
|
||||
QList<QThread*> m_InactiveList;
|
||||
};
|
||||
|
||||
class ComputerManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -100,7 +173,7 @@ private:
|
||||
int m_PollingRef;
|
||||
QReadWriteLock m_Lock;
|
||||
QMap<QString, NvComputer*> m_KnownHosts;
|
||||
QMap<QString, QThread*> m_PollThreads;
|
||||
QMap<QString, ComputerPollingEntry*> m_PollEntries;
|
||||
QMdnsEngine::Server m_MdnsServer;
|
||||
QMdnsEngine::Browser* m_MdnsBrowser;
|
||||
QMdnsEngine::Cache m_MdnsCache;
|
||||
|
||||
Reference in New Issue
Block a user