Fix persistence of deleted PCs. Fixes #82

This commit is contained in:
Cameron Gutman 2018-09-21 20:20:16 -07:00
parent af9fb0e091
commit e20bf3fbd9

View file

@ -422,10 +422,24 @@ public:
m_ComputerManager(cm) {} m_ComputerManager(cm) {}
void run() void run()
{
QThread* pollingThread;
// Only do the minimum amount of work while holding the writer lock.
// We must release it before calling saveHosts().
{ {
QWriteLocker lock(&m_ComputerManager->m_Lock); QWriteLocker lock(&m_ComputerManager->m_Lock);
QThread* pollingThread = m_ComputerManager->m_PollThreads[m_Computer->uuid]; pollingThread = m_ComputerManager->m_PollThreads[m_Computer->uuid];
m_ComputerManager->m_PollThreads.remove(m_Computer->uuid);
m_ComputerManager->m_KnownHosts.remove(m_Computer->uuid);
}
// Persist the new host list
m_ComputerManager->saveHosts();
// Delete the polling thread
if (pollingThread != nullptr) { if (pollingThread != nullptr) {
pollingThread->requestInterruption(); pollingThread->requestInterruption();
@ -438,9 +452,8 @@ public:
delete pollingThread; delete pollingThread;
} }
m_ComputerManager->m_PollThreads.remove(m_Computer->uuid); // Finally, delete the computer itself. This must be done
m_ComputerManager->m_KnownHosts.remove(m_Computer->uuid); // last because the polling thread might be using it.
delete m_Computer; delete m_Computer;
} }