From 8752dc000c86f3115fe85c1d2ee08a21862b943e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 12 Jun 2021 12:41:52 +0300 Subject: fixes #2915 (Miranda takes too long to end process) --- protocols/JabberG/src/jabber_console.cpp | 32 ++++++++++++++------------------ protocols/JabberG/src/jabber_proto.cpp | 1 - protocols/JabberG/src/jabber_proto.h | 1 - 3 files changed, 14 insertions(+), 20 deletions(-) (limited to 'protocols/JabberG/src') diff --git a/protocols/JabberG/src/jabber_console.cpp b/protocols/JabberG/src/jabber_console.cpp index 7a03299590..276b3b8f45 100644 --- a/protocols/JabberG/src/jabber_console.cpp +++ b/protocols/JabberG/src/jabber_console.cpp @@ -26,8 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -#define WM_CREATECONSOLE WM_USER+1000 - #ifndef SES_EXTENDBACKCOLOR #define SES_EXTENDBACKCOLOR 4 #endif @@ -399,6 +397,8 @@ public: m_proto->m_pDlgConsole = nullptr; CSuper::OnDestroy(); + + PostThreadMessage(m_proto->m_dwConsoleThreadId, WM_QUIT, 0, 0); } int Resizer(UTILRESIZECONTROL *urc) override @@ -572,35 +572,30 @@ void __cdecl CJabberProto::ConsoleThread(void*) { Thread_SetName("Jabber: ConsoleThread"); MThreadHandle threadLock(m_hThreadConsole); + m_dwConsoleThreadId = ::GetCurrentThreadId(); + + m_pDlgConsole = new CJabberDlgConsole(this); + m_pDlgConsole->Show(); MSG msg; while (GetMessage(&msg, nullptr, 0, 0)) { - if (msg.message == WM_CREATECONSOLE) { - m_pDlgConsole = new CJabberDlgConsole(this); - m_pDlgConsole->Show(); - continue; - } - TranslateMessage(&msg); DispatchMessage(&msg); } m_dwConsoleThreadId = 0; } -void CJabberProto::ConsoleInit() -{ - ForkThreadEx(&CJabberProto::ConsoleThread, nullptr, &m_dwConsoleThreadId); -} - void CJabberProto::ConsoleUninit() { if (m_hThreadConsole) { PostThreadMessage(m_dwConsoleThreadId, WM_QUIT, 0, 0); - if (WaitForSingleObject(m_hThreadConsole, 5000) == WAIT_TIMEOUT) { + if (MsgWaitForMultipleObjects(1, &m_hThreadConsole, FALSE, 5000, TRUE) == WAIT_TIMEOUT) TerminateThread(m_hThreadConsole, 0); + + if (m_hThreadConsole) { + CloseHandle(m_hThreadConsole); + m_hThreadConsole = nullptr; } - CloseHandle(m_hThreadConsole); - m_hThreadConsole = nullptr; } m_filterInfo.iq = m_filterInfo.msg = m_filterInfo.presence = false; @@ -611,7 +606,8 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleConsole(WPARAM, LPARAM) { if (m_pDlgConsole) SetForegroundWindow(m_pDlgConsole->GetHwnd()); - else if (m_hThreadConsole) - PostThreadMessage(m_dwConsoleThreadId, WM_CREATECONSOLE, 0, 0); + else + ForkThread(&CJabberProto::ConsoleThread); + return 0; } diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index cb222192d8..b3350947f0 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -285,7 +285,6 @@ void CJabberProto::OnModulesLoaded() m_iqManager.Start(); - ConsoleInit(); InitInfoFrame(); StatusIconData sid = {}; diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 57044acd21..762660e459 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -451,7 +451,6 @@ struct CJabberProto : public PROTO, public IJabberInterface INT_PTR __cdecl OnMenuHandleConsole(WPARAM wParam, LPARAM lParam); void __cdecl ConsoleThread(void*); - void ConsoleInit(void); void ConsoleUninit(void); bool FilterXml(const TiXmlElement *node, DWORD flags); -- cgit v1.2.3