From df6b0c988eb26339d4c7e4a1d0fe3b9717703c28 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 9 Mar 2018 19:32:32 +0300 Subject: more loop-related code cleaning --- src/mir_core/src/threads.cpp | 30 +++++++++++++----------------- src/mir_core/src/windowlist.cpp | 8 ++++---- 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'src/mir_core') diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp index 9d293c2e5e..120cdeff1e 100644 --- a/src/mir_core/src/threads.cpp +++ b/src/mir_core/src/threads.cpp @@ -218,11 +218,9 @@ MIR_CORE_DLL(void) KillObjectThreads(void* owner) { mir_cslock lck(csThreads); - for (int j = threads.getCount(); j--;) { - THREAD_WAIT_ENTRY *p = threads[j]; - if (p->pObject == owner) - threadPool[threadCount++] = p->hThread; - } + for (auto &it : threads) + if (it->pObject == owner) + threadPool[threadCount++] = it->hThread; } // is there anything to kill? @@ -250,20 +248,18 @@ MIR_CORE_DLL(void) KillObjectThreads(void* owner) static void CALLBACK KillAllThreads(HWND, UINT, UINT_PTR, DWORD) { - { - mir_cslock lck(csThreads); - for (auto &p : threads) { - char szModuleName[MAX_PATH]; - GetModuleFileNameA(p->hOwner, szModuleName, sizeof(szModuleName)); - Netlib_Logf(nullptr, "Killing thread %s:%p (%p)", szModuleName, p->dwThreadId, p->pEntryPoint); - TerminateThread(p->hThread, 9999); - CloseHandle(p->hThread); - mir_free(p); - } - - threads.destroy(); + mir_cslock lck(csThreads); + for (auto &p : threads) { + char szModuleName[MAX_PATH]; + GetModuleFileNameA(p->hOwner, szModuleName, sizeof(szModuleName)); + Netlib_Logf(nullptr, "Killing thread %s:%p (%p)", szModuleName, p->dwThreadId, p->pEntryPoint); + TerminateThread(p->hThread, 9999); + CloseHandle(p->hThread); + mir_free(p); } + threads.destroy(); + SetEvent(hThreadQueueEmpty); } diff --git a/src/mir_core/src/windowlist.cpp b/src/mir_core/src/windowlist.cpp index 13b339b8f6..a785472cbb 100644 --- a/src/mir_core/src/windowlist.cpp +++ b/src/mir_core/src/windowlist.cpp @@ -66,12 +66,12 @@ MIR_CORE_DLL(int) WindowList_Remove(MWindowList hList, HWND hwnd) { if (hList == nullptr) return 1; - for (int i = 0; i < hList->getCount(); i++) { - if ((*hList)[i].hWnd == hwnd) { - hList->remove(i); + for (auto &it : *hList) + if (it->hWnd == hwnd) { + hList->remove(it); return 0; } - } + return 1; } -- cgit v1.2.3