mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-04-12 18:56:10 +00:00
Fix improper handling of polling thread termination
This commit is contained in:
@@ -213,6 +213,10 @@ void ComputerManager::deleteHost(NvComputer* computer)
|
||||
// We must wait here because we're going to delete computer
|
||||
// and we can't do that out from underneath the poller.
|
||||
pollingThread->wait();
|
||||
|
||||
// The thread is safe to delete now
|
||||
Q_ASSERT(pollingThread->isFinished());
|
||||
delete pollingThread;
|
||||
}
|
||||
|
||||
m_PollThreads.remove(computer->uuid);
|
||||
@@ -232,8 +236,16 @@ void ComputerManager::stopPollingAsync()
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
|
||||
// The threads will delete themselves when they terminate
|
||||
QThread* thread = i.value();
|
||||
|
||||
// Let this thread delete itself when it's finished
|
||||
connect(thread, SIGNAL(finished()),
|
||||
thread, SLOT(deleteLater()));
|
||||
|
||||
// The threads will delete themselves when they terminate,
|
||||
// but we remove them from the polling threads map here.
|
||||
i.value()->requestInterruption();
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,18 +303,6 @@ bool ComputerManager::addNewHost(QString address, bool mdns)
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ComputerManager::handlePollThreadTermination(NvComputer* computer)
|
||||
{
|
||||
QWriteLocker lock(&m_Lock);
|
||||
|
||||
QThread* me = m_PollThreads[computer->uuid];
|
||||
Q_ASSERT(me != nullptr);
|
||||
|
||||
m_PollThreads.remove(computer->uuid);
|
||||
me->deleteLater();
|
||||
}
|
||||
|
||||
void
|
||||
ComputerManager::handleComputerStateChanged(NvComputer* computer)
|
||||
{
|
||||
@@ -326,8 +326,6 @@ ComputerManager::startPollingComputer(NvComputer* computer)
|
||||
}
|
||||
|
||||
PcMonitorThread* thread = new PcMonitorThread(computer);
|
||||
connect(thread, SIGNAL(terminating(NvComputer*)),
|
||||
this, SLOT(handlePollThreadTermination(NvComputer*)));
|
||||
connect(thread, SIGNAL(computerStateChanged(NvComputer*)),
|
||||
this, SLOT(handleComputerStateChanged(NvComputer*)));
|
||||
m_PollThreads[computer->uuid] = thread;
|
||||
|
||||
Reference in New Issue
Block a user