From 68c7bf3b55ca132143686ab433659c3b828760aa Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 4 May 2021 20:42:25 +0300 Subject: attempt to fix some problems on exit --- plugins/KeyboardNotify/src/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'plugins/KeyboardNotify/src') diff --git a/plugins/KeyboardNotify/src/main.cpp b/plugins/KeyboardNotify/src/main.cpp index 6bab75efb5..321aa68a9e 100644 --- a/plugins/KeyboardNotify/src/main.cpp +++ b/plugins/KeyboardNotify/src/main.cpp @@ -266,8 +266,9 @@ static void __cdecl FlashThreadFunction(void*) BYTE data, unchangedLeds; Thread_SetName("KeyboardNotify: FlashThreadFunction"); + MThreadHandle threadLock(hThread); - while (TRUE) { + while (true) { unchangedLeds = (BYTE)(LedState(VK_PAUSE) * !bFlashLed[2] + ((LedState(VK_NUMLOCK) * !bFlashLed[0]) << 1) + ((LedState(VK_CAPITAL) * !bFlashLed[1]) << 2)); GetAsyncKeyState(VK_PAUSE); // empty Pause/Break's keystroke buffer @@ -902,7 +903,7 @@ static int ModulesLoaded(WPARAM, LPARAM) mir_snwprintf(eventName, L"%s/ExitEvent", eventPrefix); hExitEvent = CreateEvent(nullptr, FALSE, FALSE, eventName); - hThread = mir_forkthread(FlashThreadFunction); + mir_forkthread(FlashThreadFunction); CreateServiceFunction(MS_KBDNOTIFY_ENABLE, EnableService); CreateServiceFunction(MS_KBDNOTIFY_DISABLE, DisableService); @@ -934,7 +935,8 @@ int CMPlugin::Unload() UnhookWindowsHooks(); // Wait for thread to exit - WaitForSingleObject(hThread, INFINITE); + if (hThread) + WaitForSingleObject(hThread, INFINITE); if (hExitEvent) CloseHandle(hExitEvent); -- cgit v1.2.3