summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-09-09 22:24:07 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-09-09 22:24:07 +0300
commit23f0b751b57b2dd9f6e912cec92364ff59b864b2 (patch)
tree9b38146c3602b5300856d00bedfc248bce5c7da0
parent77a3554616362939d78649fd257f65e464312e68 (diff)
fix for a crappy ::GetCurrentThread call that breaks all Wait* functions
-rw-r--r--include/m_system.h7
-rw-r--r--plugins/Console/src/Console.cpp7
-rw-r--r--plugins/KeyboardNotify/src/main.cpp4
-rw-r--r--plugins/NotifyAnything/NotifyAnything.vcxproj5
-rw-r--r--plugins/NotifyAnything/src/main.cpp6
-rw-r--r--plugins/Ping/src/pingthread.cpp4
-rw-r--r--plugins/Popup/src/popup_thread.cpp2
-rw-r--r--protocols/EmLanProto/src/lan.cpp4
-rw-r--r--protocols/JabberG/src/jabber_console.cpp4
9 files changed, 23 insertions, 20 deletions
diff --git a/include/m_system.h b/include/m_system.h
index 18000d6778..5226961d0f 100644
--- a/include/m_system.h
+++ b/include/m_system.h
@@ -497,18 +497,17 @@ public:
///////////////////////////////////////////////////////////////////////////////
// thread handle controller
-class MThreadHandle
+class MThreadLock
{
HANDLE &m_pHandle;
public:
- MThreadHandle(HANDLE &pHandle) :
+ __forceinline MThreadLock(HANDLE &pHandle) :
m_pHandle(pHandle)
{
- pHandle = ::GetCurrentThread();
}
- ~MThreadHandle()
+ __forceinline ~MThreadLock()
{
m_pHandle = nullptr;
}
diff --git a/plugins/Console/src/Console.cpp b/plugins/Console/src/Console.cpp
index a874f8c4cd..d6c3d5dc6e 100644
--- a/plugins/Console/src/Console.cpp
+++ b/plugins/Console/src/Console.cpp
@@ -891,10 +891,9 @@ static INT_PTR CALLBACK ConsoleDlgProc(HWND hwndDlg, UINT message, WPARAM wParam
////////////////////////////////////////////////////////////////////////////////
-
-void __cdecl ConsoleThread(void*)
+static void __cdecl ConsoleThread(void*)
{
- MThreadHandle threadLock(g_plugin.hConsoleThread);
+ MThreadLock threadLock(g_plugin.hConsoleThread);
CoInitialize(nullptr);
HWND hwnd = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_CONSOLE), nullptr, ConsoleDlgProc);
@@ -1210,7 +1209,7 @@ void InitConsole()
LoadSettings();
- mir_forkthread(ConsoleThread);
+ g_plugin.hConsoleThread = mir_forkthread(ConsoleThread);
HookEvent(ME_SYSTEM_PRESHUTDOWN, PreshutdownConsole);
HookEvent(ME_SYSTEM_MODULESLOADED, OnSystemModulesLoaded);
diff --git a/plugins/KeyboardNotify/src/main.cpp b/plugins/KeyboardNotify/src/main.cpp
index 321aa68a9e..322ba0ec93 100644
--- a/plugins/KeyboardNotify/src/main.cpp
+++ b/plugins/KeyboardNotify/src/main.cpp
@@ -266,7 +266,7 @@ static void __cdecl FlashThreadFunction(void*)
BYTE data, unchangedLeds;
Thread_SetName("KeyboardNotify: FlashThreadFunction");
- MThreadHandle threadLock(hThread);
+ MThreadLock threadLock(hThread);
while (true) {
unchangedLeds = (BYTE)(LedState(VK_PAUSE) * !bFlashLed[2] + ((LedState(VK_NUMLOCK) * !bFlashLed[0]) << 1) + ((LedState(VK_CAPITAL) * !bFlashLed[1]) << 2));
@@ -903,7 +903,7 @@ static int ModulesLoaded(WPARAM, LPARAM)
mir_snwprintf(eventName, L"%s/ExitEvent", eventPrefix);
hExitEvent = CreateEvent(nullptr, FALSE, FALSE, eventName);
- mir_forkthread(FlashThreadFunction);
+ hThread = mir_forkthread(FlashThreadFunction);
CreateServiceFunction(MS_KBDNOTIFY_ENABLE, EnableService);
CreateServiceFunction(MS_KBDNOTIFY_DISABLE, DisableService);
diff --git a/plugins/NotifyAnything/NotifyAnything.vcxproj b/plugins/NotifyAnything/NotifyAnything.vcxproj
index 991f77c9a7..16d172e8cc 100644
--- a/plugins/NotifyAnything/NotifyAnything.vcxproj
+++ b/plugins/NotifyAnything/NotifyAnything.vcxproj
@@ -39,4 +39,9 @@
<ResourceCompile Include="res\NotifyAnything.rc" />
<ResourceCompile Include="res\Version.rc" />
</ItemGroup>
+ <ItemDefinitionGroup>
+ <ClCompile>
+ <ExceptionHandling>Sync</ExceptionHandling>
+ </ClCompile>
+ </ItemDefinitionGroup>
</Project> \ No newline at end of file
diff --git a/plugins/NotifyAnything/src/main.cpp b/plugins/NotifyAnything/src/main.cpp
index 6c0c7fb9ae..bcfee4a9b3 100644
--- a/plugins/NotifyAnything/src/main.cpp
+++ b/plugins/NotifyAnything/src/main.cpp
@@ -837,7 +837,7 @@ void initWinsock()
void __cdecl udptcpThreadFunc(void *useUdp)
{
- MThreadHandle threadLock(useUdp ? g_udp_thread : g_tcp_thread);
+ MThreadLock threadLock(useUdp ? g_udp_thread : g_tcp_thread);
try
{
@@ -948,8 +948,8 @@ void __cdecl udptcpThreadFunc(void *useUdp)
void start_threads()
{
g_exit_threads = false;
- mir_forkthread(udptcpThreadFunc, (void *)1);
- mir_forkthread(udptcpThreadFunc);
+ g_udp_thread = mir_forkthread(udptcpThreadFunc, (void *)1);
+ g_tcp_thread = mir_forkthread(udptcpThreadFunc);
}
void stop_threads()
diff --git a/plugins/Ping/src/pingthread.cpp b/plugins/Ping/src/pingthread.cpp
index a57266e6f1..9921eff5d2 100644
--- a/plugins/Ping/src/pingthread.cpp
+++ b/plugins/Ping/src/pingthread.cpp
@@ -74,7 +74,7 @@ void SetProtoStatus(wchar_t *pszLabel, char *pszProto, int if_status, int new_st
void __cdecl sttCheckStatusThreadProc(void*)
{
- MThreadHandle threadLock(status_update_thread);
+ MThreadLock threadLock(status_update_thread);
clock_t start_t = clock(), end_t;
while (!get_thread_finished()) {
@@ -904,7 +904,7 @@ void InitList()
ReloadFont(0, 0);
- mir_forkthread(sttCheckStatusThreadProc);
+ status_update_thread = mir_forkthread(sttCheckStatusThreadProc);
}
void DeinitList()
diff --git a/plugins/Popup/src/popup_thread.cpp b/plugins/Popup/src/popup_thread.cpp
index 76113d68ec..01eab8dbeb 100644
--- a/plugins/Popup/src/popup_thread.cpp
+++ b/plugins/Popup/src/popup_thread.cpp
@@ -210,7 +210,7 @@ static LRESULT CALLBACK PopupThreadManagerWndProc(HWND hwnd, UINT message, WPARA
static unsigned __stdcall PopupThread(void *)
{
Thread_SetName("Popup: PopupThread");
- MThreadHandle threadLock(hThread);
+ MThreadLock threadLock(hThread);
// Create manager window
WNDCLASSEX wcl;
diff --git a/protocols/EmLanProto/src/lan.cpp b/protocols/EmLanProto/src/lan.cpp
index 42787169d2..8d4d07dc53 100644
--- a/protocols/EmLanProto/src/lan.cpp
+++ b/protocols/EmLanProto/src/lan.cpp
@@ -146,7 +146,7 @@ void CLan::StartListen()
return;
}
- mir_forkthread(ListenProc, this);
+ m_hListenThread = mir_forkthread(ListenProc, this);
m_hAcceptTCPThread = mir_forkthread(AcceptTCPProc, this);
if (m_hListenThread == nullptr || m_hAcceptTCPThread == nullptr) {
m_mode = LM_ON;
@@ -179,7 +179,7 @@ void CLan::Listen()
if (m_mode != LM_LISTEN)
return;
- MThreadHandle threadLock(m_hListenThread);
+ MThreadLock threadLock(m_hListenThread);
mir_ptr<char> buf((char*)mir_alloc(65536));
while (true) {
diff --git a/protocols/JabberG/src/jabber_console.cpp b/protocols/JabberG/src/jabber_console.cpp
index 276b3b8f45..94a9fc9c95 100644
--- a/protocols/JabberG/src/jabber_console.cpp
+++ b/protocols/JabberG/src/jabber_console.cpp
@@ -571,7 +571,7 @@ public:
void __cdecl CJabberProto::ConsoleThread(void*)
{
Thread_SetName("Jabber: ConsoleThread");
- MThreadHandle threadLock(m_hThreadConsole);
+ MThreadLock threadLock(m_hThreadConsole);
m_dwConsoleThreadId = ::GetCurrentThreadId();
m_pDlgConsole = new CJabberDlgConsole(this);
@@ -607,7 +607,7 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleConsole(WPARAM, LPARAM)
if (m_pDlgConsole)
SetForegroundWindow(m_pDlgConsole->GetHwnd());
else
- ForkThread(&CJabberProto::ConsoleThread);
+ m_hThreadConsole = ForkThreadEx(&CJabberProto::ConsoleThread, 0, &m_dwConsoleThreadId);
return 0;
}