Skip to content

Commit

Permalink
Fix race-condition in PowerRename progress UI (#12771)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianjoneill committed Aug 18, 2021
1 parent ec08a1d commit 31a5d49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/modules/powerrename/ui/PowerRenameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,11 @@ HRESULT CPowerRenameProgressUI::Start()
m_canceled = false;
AddRef();
m_workerThreadHandle = CreateThread(nullptr, 0, s_workerThread, this, 0, nullptr);
if (!m_workerThreadHandle)
if (m_workerThreadHandle)
{
m_loadingThread = true;
}
else
{
Release();
}
Expand Down Expand Up @@ -1557,6 +1561,7 @@ DWORD WINAPI CPowerRenameProgressUI::s_workerThread(_In_ void* pv)
SetTimer(hwndMessage, TIMERID_CHECKCANCELED, CANCEL_CHECK_INTERVAL, nullptr);
sppd->StartProgressDialog(NULL, NULL, PROGDLG_MARQUEEPROGRESS, NULL);
}
pThis->m_loadingThread = false;

while (pThis->m_sppd && !sppd->HasUserCancelled())
{
Expand Down Expand Up @@ -1591,6 +1596,11 @@ HRESULT CPowerRenameProgressUI::Stop()

void CPowerRenameProgressUI::_Cleanup()
{
while (m_loadingThread.load())
{
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}

if (m_sppd)
{
m_sppd->StopProgressDialog();
Expand Down
1 change: 1 addition & 0 deletions src/modules/powerrename/ui/PowerRenameUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CPowerRenameProgressUI :

long m_refCount = 0;
bool m_canceled = false;
std::atomic<bool> m_loadingThread{ false };
HANDLE m_workerThreadHandle = nullptr;
CComPtr<IProgressDialog> m_sppd;
};
Expand Down

0 comments on commit 31a5d49

Please sign in to comment.