mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-11-10 05:34:17 +00:00
Implement a proper destructor for ComputerManager to prevent polling threads from living beyond QGuiApplication
This commit is contained in:
parent
06501bd4b7
commit
5ee1358712
2 changed files with 52 additions and 0 deletions
|
@ -286,6 +286,56 @@ ComputerManager::ComputerManager(QObject *parent)
|
|||
settings.endArray();
|
||||
}
|
||||
|
||||
ComputerManager::~ComputerManager()
|
||||
{
|
||||
QWriteLocker lock(&m_Lock);
|
||||
|
||||
// Delete machines that haven't been resolved yet
|
||||
while (!m_PendingResolution.isEmpty()) {
|
||||
MdnsPendingComputer* computer = m_PendingResolution.first();
|
||||
delete computer;
|
||||
m_PendingResolution.removeFirst();
|
||||
}
|
||||
|
||||
// Delete the browser to stop discovery
|
||||
delete m_MdnsBrowser;
|
||||
m_MdnsBrowser = nullptr;
|
||||
|
||||
{
|
||||
QMutableMapIterator<QString, QThread*> i(m_PollThreads);
|
||||
|
||||
// Interrupt all polling threads
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
i.value()->requestInterruption();
|
||||
}
|
||||
|
||||
// Wait for all threads to terminate before destroying
|
||||
// the NvComputer objects.
|
||||
i.toFront();
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
|
||||
QThread* thread = i.value();
|
||||
thread->wait();
|
||||
delete thread;
|
||||
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
QMutableMapIterator<QString, NvComputer*> i(m_KnownHosts);
|
||||
|
||||
// Destroy all NvComputer objects
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
delete i.value();
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ComputerManager::saveHosts()
|
||||
{
|
||||
QSettings settings;
|
||||
|
|
|
@ -249,6 +249,8 @@ class ComputerManager : public QObject
|
|||
public:
|
||||
explicit ComputerManager(QObject *parent = nullptr);
|
||||
|
||||
virtual ~ComputerManager();
|
||||
|
||||
Q_INVOKABLE void startPolling();
|
||||
|
||||
Q_INVOKABLE void stopPollingAsync();
|
||||
|
|
Loading…
Reference in a new issue