summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-07-26 21:40:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-07-26 21:40:50 +0300
commit1019387a8f6ccc087a113f138c5237146492a356 (patch)
tree50ef616016686e43ae119333ebac88bc90b2ff11
parentd61bc49d53578c26b50531fdec1bbd633e19b6ac (diff)
fixes #1527 (Remove obsolete g_hMainThread and QueueUSerAPC from plugins)
-rw-r--r--plugins/BasicHistory/src/BasicHistory.cpp6
-rw-r--r--plugins/BasicHistory/src/Scheduler.cpp16
-rw-r--r--plugins/HTTPServer/src/GuiElements.cpp36
-rw-r--r--plugins/HTTPServer/src/GuiElements.h1
-rw-r--r--plugins/HTTPServer/src/main.cpp3
-rw-r--r--plugins/Ping/src/ping.cpp3
-rw-r--r--plugins/Ping/src/pingthread.cpp1
-rw-r--r--plugins/Ping/src/stdafx.h1
-rw-r--r--plugins/Ping/src/utils.cpp5
-rw-r--r--protocols/IcqOscarJ/src/utilities.cpp6
-rw-r--r--protocols/Sametime/src/sametime_session.cpp10
-rw-r--r--src/mir_core/src/threads.cpp2
12 files changed, 22 insertions, 68 deletions
diff --git a/plugins/BasicHistory/src/BasicHistory.cpp b/plugins/BasicHistory/src/BasicHistory.cpp
index a371fcdfa0..091d9b15d9 100644
--- a/plugins/BasicHistory/src/BasicHistory.cpp
+++ b/plugins/BasicHistory/src/BasicHistory.cpp
@@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MS_HISTORY_EXECUTE_TASK "BasicHistory/ExecuteTask"
HCURSOR hCurSplitNS, hCurSplitWE;
-HANDLE g_hMainThread = nullptr;
HANDLE *hEventIcons = nullptr;
int iconsNum = 3;
@@ -237,7 +236,6 @@ int ModulesLoaded(WPARAM, LPARAM)
int CMPlugin::Load()
{
hTaskMainMenu = nullptr;
- DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &g_hMainThread, 0, FALSE, DUPLICATE_SAME_ACCESS);
hCurSplitNS = LoadCursor(nullptr, IDC_SIZENS);
hCurSplitWE = LoadCursor(nullptr, IDC_SIZEWE);
@@ -261,10 +259,6 @@ int CMPlugin::Load()
int CMPlugin::Unload()
{
- if (g_hMainThread)
- CloseHandle(g_hMainThread);
- g_hMainThread = nullptr;
-
HistoryWindow::Deinit();
DestroyCursor(hCurSplitNS);
diff --git a/plugins/BasicHistory/src/Scheduler.cpp b/plugins/BasicHistory/src/Scheduler.cpp
index 26dfcb3fb2..57b93a97c8 100644
--- a/plugins/BasicHistory/src/Scheduler.cpp
+++ b/plugins/BasicHistory/src/Scheduler.cpp
@@ -22,8 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "HistoryWindow.h"
// Sorry for plain C implementation
-#define MODULENAME "BasicHistory"
-extern HANDLE g_hMainThread;
+#define MODULENAME "BasicHistory"
+
bool bPopupsEnabled;
bool DoTask(TaskOptions& to);
bool IsValidTask(TaskOptions& to, std::list<TaskOptions>* top = nullptr, std::wstring* err = nullptr, std::wstring* errDescr = nullptr);
@@ -217,7 +217,7 @@ bool IsValidTask(TaskOptions& to, std::list<TaskOptions>* top, std::wstring* err
return true;
}
-static void CALLBACK DoRebuildEventsInMainAPCFunc(ULONG_PTR dwParam)
+static INT_PTR CALLBACK DoRebuildEventsInMainAPCFunc(void *dwParam)
{
MCONTACT *contacts = (MCONTACT*)dwParam;
size_t size = (size_t)contacts[0];
@@ -225,6 +225,7 @@ static void CALLBACK DoRebuildEventsInMainAPCFunc(ULONG_PTR dwParam)
HistoryWindow::RebuildEvents(contacts[i]);
delete[] contacts;
+ return 0;
}
bool DoTask(TaskOptions& to)
@@ -416,7 +417,7 @@ bool DoTask(TaskOptions& to)
for (std::list<MCONTACT>::iterator it = contactList.begin(); it != contactList.end(); ++it)
pContacts[i++] = *it;
- QueueUserAPC(DoRebuildEventsInMainAPCFunc, g_hMainThread, (ULONG_PTR)pContacts);
+ CallFunctionSync(DoRebuildEventsInMainAPCFunc, pContacts);
}
}
@@ -788,11 +789,12 @@ bool GetNextExportTime(bool init, time_t now)
return isExport;
}
-static void CALLBACK DoTaskFinishInMainAPCFunc(ULONG_PTR dwParam)
+static INT_PTR CALLBACK DoTaskFinishInMainAPCFunc(void *param)
{
- wchar_t *item = (wchar_t*)dwParam;
+ wchar_t *item = (wchar_t*)param;
MessageBox(nullptr, item, TranslateT("Task finished"), MB_OK | MB_ICONINFORMATION);
delete[] item;
+ return 0;
}
bool ExecuteCurrentTask(time_t now)
@@ -843,7 +845,7 @@ bool ExecuteCurrentTask(time_t now)
mir_snwprintf(name, size, TranslateT("Task '%s' execution failed"), to.taskName.c_str());
else
mir_snwprintf(name, size, TranslateT("Task '%s' finished successfully"), to.taskName.c_str());
- QueueUserAPC(DoTaskFinishInMainAPCFunc, g_hMainThread, (ULONG_PTR)name);
+ CallFunctionSync(DoTaskFinishInMainAPCFunc, name);
}
}
}
diff --git a/plugins/HTTPServer/src/GuiElements.cpp b/plugins/HTTPServer/src/GuiElements.cpp
index 726f5947da..5b0cd2d32a 100644
--- a/plugins/HTTPServer/src/GuiElements.cpp
+++ b/plugins/HTTPServer/src/GuiElements.cpp
@@ -32,7 +32,6 @@ static HANDLE hEventOptionsInitialize = nullptr;
HWND hwndStatsticView = nullptr;
bool bLastAutoRefress = false;
-HANDLE hMainThread;
bool bShowPopups = true;
@@ -1357,9 +1356,9 @@ int OptionsInitialize(WPARAM wParam, LPARAM /*lParam*/)
// Developer : KN
/////////////////////////////////////////////////////////////////////
-void CALLBACK MainThreadCallback(ULONG_PTR dwParam)
+void CALLBACK MainThreadCallback(void *param)
{
- POPUPDATAT *pclData = (POPUPDATAT*)dwParam;
+ POPUPDATAT *pclData = (POPUPDATAT*)param;
if (db_get_b(NULL, MODULENAME, "WriteLogFile", 0) != 0)
LogEvent(pclData->lpzContactName, pclData->lpzText);
@@ -1383,7 +1382,7 @@ void CALLBACK MainThreadCallback(ULONG_PTR dwParam)
// Developer : KN, Houdini
/////////////////////////////////////////////////////////////////////
-void CALLBACK OpenStatisticViewFromPopupProc(ULONG_PTR /* dwParam */)
+static void CALLBACK OpenStatisticViewFromPopupProc(void*)
{
nShowStatisticsView(0, 0);
}
@@ -1394,7 +1393,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
switch (message) {
case WM_LBUTTONDOWN:
- QueueUserAPC(OpenStatisticViewFromPopupProc, hMainThread, 0);
+ CallFunctionAsync(OpenStatisticViewFromPopupProc, 0);
PUDeletePopup(hWnd);
return 0;
@@ -1429,12 +1428,8 @@ void ShowPopupWindow(const char * pszName, const char * pszText, COLORREF ColorB
strncpy(pclData->lpzContactName, pszName, sizeof(pclData->lpzContactName) - 1); // -1 so that there aways will be a null termination !!
strncpy(pclData->lpzText, pszText, sizeof(pclData->lpzText) - 1);
pclData->colorBack = ColorBack;
- //ppd.colorText = colorText;
pclData->PluginWindowProc = PopupWindowProc;
- //Now that every field has been filled, we want to see the popup.
-
- //CallService(MS_POPUP_ADDPOPUP, (WPARAM)&ppd, 0);
- QueueUserAPC(MainThreadCallback, hMainThread, (ULONG_PTR)pclData);
+ CallFunctionAsync(MainThreadCallback, pclData);
}
/////////////////////////////////////////////////////////////////////
@@ -1457,9 +1452,6 @@ void InitGuiElements()
stInitCom.dwICC = ICC_INTERNET_CLASSES;
InitCommonControlsEx(&stInitCom);
- //hMainThread = GetCurrentThread();
- DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hMainThread, THREAD_SET_CONTEXT, FALSE, 0);
-
sUrlAddress = DBGetString(NULL, MODULENAME, "UrlAddress", szDefaultUrlAddress);
sPageKeyword = DBGetString(NULL, MODULENAME, "PageKeyword", szDefaultPageKeyword);
@@ -1489,21 +1481,3 @@ void InitGuiElements()
bShowPopups = db_get_b(NULL, MODULENAME, "ShowPopups", bShowPopups) != 0;
}
-
-/////////////////////////////////////////////////////////////////////
-// Member Function : UninitGuiElements
-// Type : Global
-// Parameters : None
-// Returns : void
-// Description :
-//
-// References : -
-// Remarks : -
-// Created : 031011, 11 oktober 2003
-// Developer : KN
-/////////////////////////////////////////////////////////////////////
-
-void UnInitGuiElements()
-{
- CloseHandle(hMainThread);
-}
diff --git a/plugins/HTTPServer/src/GuiElements.h b/plugins/HTTPServer/src/GuiElements.h
index 0ce1d11814..23ca03d032 100644
--- a/plugins/HTTPServer/src/GuiElements.h
+++ b/plugins/HTTPServer/src/GuiElements.h
@@ -21,7 +21,6 @@
#include <windows.h>
void InitGuiElements();
-void UnInitGuiElements();
void UpdateStatisticsView();
void ShowPopupWindow(const char * pszName, const char * pszText, COLORREF ColorBack = 0);
void SendLinkToUser(WPARAM wParam, char *pszSrvPath); // Add By Sergio Vieira Rolanski
diff --git a/plugins/HTTPServer/src/main.cpp b/plugins/HTTPServer/src/main.cpp
index e951994a83..159b763bd3 100644
--- a/plugins/HTTPServer/src/main.cpp
+++ b/plugins/HTTPServer/src/main.cpp
@@ -790,11 +790,8 @@ int nSystemShutdown(WPARAM /*wparam*/, LPARAM /*lparam*/)
}
pclFirstNode = nullptr;
- UnInitGuiElements();
-
db_set_b(NULL, MODULENAME, "IndexCreationMode", (BYTE)indexCreationMode);
FreeIndexHTMLTemplate();
-
return 0;
}
diff --git a/plugins/Ping/src/ping.cpp b/plugins/Ping/src/ping.cpp
index ad55a54a90..da44e3ac1a 100644
--- a/plugins/Ping/src/ping.cpp
+++ b/plugins/Ping/src/ping.cpp
@@ -121,7 +121,6 @@ int CMPlugin::Load()
use_raw_ping = false;
db_set_b(0, MODULENAME, "UsingRawSockets", (BYTE)use_raw_ping);
- DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0);
hWakeEvent = CreateEvent(nullptr, FALSE, FALSE, L"Local\\ThreadWaitEvent");
// create services before loading options - so we can have the 'getlogfilename' service!
@@ -147,8 +146,6 @@ int CMPlugin::Unload()
{
SavePingList(0, 0);
- CloseHandle(mainThread);
-
if (options.logging)
CallService(MODULENAME "/Log", (WPARAM)L"stop", 0);
diff --git a/plugins/Ping/src/pingthread.cpp b/plugins/Ping/src/pingthread.cpp
index 09eba92fb0..f17298f6e1 100644
--- a/plugins/Ping/src/pingthread.cpp
+++ b/plugins/Ping/src/pingthread.cpp
@@ -4,7 +4,6 @@ int upCount, total = 0;
size_t list_size = 0;
-HANDLE mainThread;
HANDLE hWakeEvent = nullptr;
// thread protected variables
diff --git a/plugins/Ping/src/stdafx.h b/plugins/Ping/src/stdafx.h
index 257c56d6f8..80b2da686d 100644
--- a/plugins/Ping/src/stdafx.h
+++ b/plugins/Ping/src/stdafx.h
@@ -129,7 +129,6 @@ extern HistoryMap history_map;
extern PINGLIST list_items;
extern HANDLE reload_event_handle;
extern mir_cs list_cs;
-extern HANDLE mainThread;
extern HANDLE hWakeEvent;
extern mir_cs thread_finished_cs, list_changed_cs, data_list_cs;
diff --git a/plugins/Ping/src/utils.cpp b/plugins/Ping/src/utils.cpp
index 2f603ec3a0..58111c7f15 100644
--- a/plugins/Ping/src/utils.cpp
+++ b/plugins/Ping/src/utils.cpp
@@ -16,7 +16,7 @@ LRESULT CALLBACK NullWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l
return DefWindowProc(hWnd, message, wParam, lParam);
}
-void CALLBACK sttMainThreadCallback(ULONG_PTR dwParam)
+static INT_PTR CALLBACK sttMainThreadCallback(void *dwParam)
{
POPUPDATAT* ppd = (POPUPDATAT*)dwParam;
@@ -24,6 +24,7 @@ void CALLBACK sttMainThreadCallback(ULONG_PTR dwParam)
PUAddPopupT(ppd);
free(ppd);
+ return 0;
}
void __stdcall ShowPopup(wchar_t *line1, wchar_t *line2, int flags)
@@ -48,7 +49,7 @@ void __stdcall ShowPopup(wchar_t *line1, wchar_t *line2, int flags)
ppd->PluginWindowProc = NullWindowProc;
ppd->PluginData = nullptr;
- QueueUserAPC(sttMainThreadCallback, mainThread, (ULONG_PTR)ppd);
+ CallFunctionSync(sttMainThreadCallback, ppd);
}
else{
MessageBox(nullptr, line2, _A2W(MODULENAME) L" Message", MB_OK | MB_ICONINFORMATION);
diff --git a/protocols/IcqOscarJ/src/utilities.cpp b/protocols/IcqOscarJ/src/utilities.cpp
index d94cb53319..05d3358153 100644
--- a/protocols/IcqOscarJ/src/utilities.cpp
+++ b/protocols/IcqOscarJ/src/utilities.cpp
@@ -1322,9 +1322,11 @@ DWORD ICQWaitForSingleObject(HANDLE hObject, DWORD dwMilliseconds, int bWaitAlwa
{
DWORD dwResult;
- do { // will get WAIT_IO_COMPLETION for QueueUserAPC(), ignore it unless terminating
+ // will get WAIT_IO_COMPLETION for QueueUserAPC(), ignore it unless terminating
+ do {
dwResult = WaitForSingleObjectEx(hObject, dwMilliseconds, TRUE);
- } while (dwResult == WAIT_IO_COMPLETION && (bWaitAlways || !Miranda_IsTerminated()));
+ }
+ while (dwResult == WAIT_IO_COMPLETION && (bWaitAlways || !Miranda_IsTerminated()));
return dwResult;
}
diff --git a/protocols/Sametime/src/sametime_session.cpp b/protocols/Sametime/src/sametime_session.cpp
index 686f5e889d..287d2794d8 100644
--- a/protocols/Sametime/src/sametime_session.cpp
+++ b/protocols/Sametime/src/sametime_session.cpp
@@ -331,16 +331,6 @@ void CSametimeProto::SetSessionAwayMessage(int status, const wchar_t* msgT)
SetSessionStatus(status); // update current away message
}
-static VOID CALLBACK NullAPC(DWORD_PTR)
-{
- // This function intentionally left blank
-}
-
-void WakeThread(HANDLE hThread)
-{
- QueueUserAPC(NullAPC, hThread, 0);
-}
-
void __cdecl CSametimeProto::KeepAliveThread(void*)
{
int i = 120;
diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp
index 625b84781c..543e2f4a74 100644
--- a/src/mir_core/src/threads.cpp
+++ b/src/mir_core/src/threads.cpp
@@ -40,8 +40,8 @@ static void __stdcall DummyAPCFunc(ULONG_PTR)
static int MirandaWaitForMutex(HANDLE hEvent)
{
+ // will get WAIT_IO_COMPLETE for QueueUserAPC() which isnt a result
for (;;) {
- // will get WAIT_IO_COMPLETE for QueueUserAPC() which isnt a result
DWORD rc = MsgWaitForMultipleObjectsEx(1, &hEvent, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
if (rc == WAIT_OBJECT_0 + 1) {
MSG msg;