properly handle thread when AOT is destroyed (#19489)

This commit is contained in:
Davide Giacometti
2022-07-18 13:43:01 +02:00
committed by GitHub
parent 996a235e12
commit af4dc80ce9
2 changed files with 8 additions and 6 deletions

View File

@@ -56,11 +56,12 @@ AlwaysOnTop::~AlwaysOnTop()
{
if (m_hPinEvent)
{
SetEvent(m_hPinEvent);
m_thread.join();
CloseHandle(m_hPinEvent);
}
m_running = false;
m_thread.join();
CleanUp();
}
@@ -274,12 +275,12 @@ void AlwaysOnTop::RegisterLLKH()
Logger::warn(L"Failed to create pinEvent. {}", get_last_error_or_default(GetLastError()));
return;
}
m_thread = std::thread([this]() {
MSG msg;
while (1)
while (m_running)
{
DWORD dwEvt = MsgWaitForMultipleObjects(1, &m_hPinEvent, false, INFINITE, QS_ALLINPUT);
DWORD dwEvt = MsgWaitForMultipleObjects(1, &m_hPinEvent, false, 0, QS_ALLINPUT);
switch (dwEvt)
{
case WAIT_OBJECT_0:
@@ -296,7 +297,7 @@ void AlwaysOnTop::RegisterLLKH()
}
break;
default:
return false;
break;
}
}
});

View File

@@ -50,6 +50,7 @@ private:
HANDLE m_hPinEvent;
std::thread m_thread;
const bool m_useCentralizedLLKH;
bool m_running = true;
LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
void HandleWinHookEvent(WinHookEvent* data) noexcept;