Fix race-condition in PowerRename progress UI (#12771)

This commit is contained in:
Ian O'Neill 2021-08-18 12:20:51 +01:00 committed by GitHub
parent ec08a1d44a
commit 31a5d49246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -1525,7 +1525,11 @@ HRESULT CPowerRenameProgressUI::Start()
m_canceled = false; m_canceled = false;
AddRef(); AddRef();
m_workerThreadHandle = CreateThread(nullptr, 0, s_workerThread, this, 0, nullptr); m_workerThreadHandle = CreateThread(nullptr, 0, s_workerThread, this, 0, nullptr);
if (!m_workerThreadHandle) if (m_workerThreadHandle)
{
m_loadingThread = true;
}
else
{ {
Release(); Release();
} }
@ -1557,6 +1561,7 @@ DWORD WINAPI CPowerRenameProgressUI::s_workerThread(_In_ void* pv)
SetTimer(hwndMessage, TIMERID_CHECKCANCELED, CANCEL_CHECK_INTERVAL, nullptr); SetTimer(hwndMessage, TIMERID_CHECKCANCELED, CANCEL_CHECK_INTERVAL, nullptr);
sppd->StartProgressDialog(NULL, NULL, PROGDLG_MARQUEEPROGRESS, NULL); sppd->StartProgressDialog(NULL, NULL, PROGDLG_MARQUEEPROGRESS, NULL);
} }
pThis->m_loadingThread = false;
while (pThis->m_sppd && !sppd->HasUserCancelled()) while (pThis->m_sppd && !sppd->HasUserCancelled())
{ {
@ -1591,6 +1596,11 @@ HRESULT CPowerRenameProgressUI::Stop()
void CPowerRenameProgressUI::_Cleanup() void CPowerRenameProgressUI::_Cleanup()
{ {
while (m_loadingThread.load())
{
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
if (m_sppd) if (m_sppd)
{ {
m_sppd->StopProgressDialog(); m_sppd->StopProgressDialog();

View File

@ -68,6 +68,7 @@ private:
long m_refCount = 0; long m_refCount = 0;
bool m_canceled = false; bool m_canceled = false;
std::atomic<bool> m_loadingThread{ false };
HANDLE m_workerThreadHandle = nullptr; HANDLE m_workerThreadHandle = nullptr;
CComPtr<IProgressDialog> m_sppd; CComPtr<IProgressDialog> m_sppd;
}; };