From 10091bbca1380a1d8e3b9d61b8c175490036af5b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 2 Dec 2016 22:21:55 +0300 Subject: old shit died now there's no need to create fake services & events --- bin10/lib/mir_app.lib | Bin 88272 -> 88586 bytes bin10/lib/mir_app64.lib | Bin 84274 -> 84594 bytes bin12/lib/mir_app.lib | Bin 88272 -> 88586 bytes bin12/lib/mir_app64.lib | Bin 84274 -> 84594 bytes bin14/lib/mir_app.lib | Bin 88272 -> 88586 bytes bin14/lib/mir_app64.lib | Bin 84274 -> 84594 bytes include/delphi/m_core.inc | 8 +++ include/delphi/m_system.inc | 38 --------------- include/m_system.h | 57 +++++----------------- plugins/CryptoPP/crypto/src/wait.cpp | 2 + plugins/Sessions/Src/Main.cpp | 12 +---- plugins/Sessions/Src/stdafx.h | 2 - plugins/TopToolBar/src/toolbar.cpp | 7 +-- plugins/TopToolBar/src/toolbarwnd.cpp | 10 +--- plugins/Watrack/watrack.dpr | 15 +----- protocols/MRA/src/MraAvatars.cpp | 6 +-- protocols/Sametime/src/glib/gpoll.c | 4 +- src/mir_app/src/db_ini.cpp | 11 ++--- src/mir_app/src/menu_utils.cpp | 12 +---- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/miranda.cpp | 89 +++++++++++++++++++--------------- src/mir_app/src/srmm_toolbar.cpp | 10 +--- 23 files changed, 95 insertions(+), 190 deletions(-) diff --git a/bin10/lib/mir_app.lib b/bin10/lib/mir_app.lib index 2c67e57368..41dd7ad925 100644 Binary files a/bin10/lib/mir_app.lib and b/bin10/lib/mir_app.lib differ diff --git a/bin10/lib/mir_app64.lib b/bin10/lib/mir_app64.lib index 87d51a3788..304852b2ac 100644 Binary files a/bin10/lib/mir_app64.lib and b/bin10/lib/mir_app64.lib differ diff --git a/bin12/lib/mir_app.lib b/bin12/lib/mir_app.lib index 2c67e57368..41dd7ad925 100644 Binary files a/bin12/lib/mir_app.lib and b/bin12/lib/mir_app.lib differ diff --git a/bin12/lib/mir_app64.lib b/bin12/lib/mir_app64.lib index 87d51a3788..304852b2ac 100644 Binary files a/bin12/lib/mir_app64.lib and b/bin12/lib/mir_app64.lib differ diff --git a/bin14/lib/mir_app.lib b/bin14/lib/mir_app.lib index 2c67e57368..41dd7ad925 100644 Binary files a/bin14/lib/mir_app.lib and b/bin14/lib/mir_app.lib differ diff --git a/bin14/lib/mir_app64.lib b/bin14/lib/mir_app64.lib index 87d51a3788..304852b2ac 100644 Binary files a/bin14/lib/mir_app64.lib and b/bin14/lib/mir_app64.lib differ diff --git a/include/delphi/m_core.inc b/include/delphi/m_core.inc index 3428109f97..f5af2c3ca4 100644 --- a/include/delphi/m_core.inc +++ b/include/delphi/m_core.inc @@ -152,6 +152,14 @@ function CallProtoService(const szModule:PAnsiChar;const szService:PAnsiChar;wPa function mir_urlEncode(url:PAnsiChar): PAnsiChar; stdcall; external CoreDLL name 'mir_urlEncode'; +/////////////////////////////////////////////////////////////////////////////// +// wait handles + +type + MWaitableStub = procedure; stdcall; + +procedure Miranda_WaitOnHandle(pFunc:MWaitableStub; hEvent:THANDLE); stdcall; external AppDll; + /////////////////////////////////////////////////////////////////////////////// // exceptions diff --git a/include/delphi/m_system.inc b/include/delphi/m_system.inc index 55bd148a67..2567b8c2b9 100644 --- a/include/delphi/m_system.inc +++ b/include/delphi/m_system.inc @@ -96,44 +96,6 @@ const } MS_SYSTEM_GETVERSIONTEXT:PAnsiChar = 'Miranda/System/GetVersionText'; - { Adds a HANDLE to the list to be checked in the main message loop v0.1.2.0+ - wParam=(WPARAM)(HANDLE)hObject - lParam=(LPARAM)(const AnsiChar*)pszService - returns 0 on success or nonzero on failure - Causes pszService to be CallService()d (wParam=hObject,lParam=0) from the - main thread whenever hObject is signalled. - The Miranda message loop has a MsgWaitForMultipleObjects() call in it to - implement this feature. See the documentation for that function for - information on what objects are supported. - There is a limit of MAXIMUM_WAIT_OBJECTS minus one (MWO is defined in winnt.h - to be 64) on the number of handles MSFMO() can process. This service will - return nonzero if that many handles are already being waited on. - As of writing, the following parts of Miranda are thread-safe, so can be - called from any thread: - All of modules.h except NotifyEventHooks() - Read-only parts of m_database.h (since the write parts will call hooks) - All of m_langpack.h - for all other routines your mileage may vary, but I would strongly recommend - that you call them from the main thread, or ask about it on plugin-dev if you - think it really ought to work. - Update during 0.1.2.0 development, 16/10/01: - NotifyEventHooks() now translates all calls into the context of the main - thread, which means that all of m_database.h is now completely safe. - Update during 0.1.2.2 development, 17/4/02: - The main thread's message loop now also deals with asynchronous procedure - calls. Loop up QueueUserAPC() for a neater way to accomplish a lot of the - things that used to require ms_system_waitonhandle. - Miranda is compiled with the multithreaded runtime - don't forget to do the - same with your plugin. - } - MS_SYSTEM_WAITONHANDLE:PAnsiChar = 'Miranda/System/WaitOnHandle'; - - {Removes a HANDLE from the wait list v0.1.2.0+ } - {wParam=(WPARAM)(HANDLE)hObject } - {lParam=0 } - {returns 0 on success or nonzero on failure. } - MS_SYSTEM_REMOVEWAIT:PAnsiChar = 'Miranda/System/RemoveWait'; - { wParam=0 lParam=0 diff --git a/include/m_system.h b/include/m_system.h index 4d5757c593..f0b16ea385 100644 --- a/include/m_system.h +++ b/include/m_system.h @@ -91,54 +91,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //version 1.2.3.3210 is 0x0001, 0x0002, 0x0003, 0x0C8a #define MS_SYSTEM_GETFILEVERSION "Miranda/System/GetFileVersion" -//gets the version of Miranda encoded as text v0.1.0.1+ -//wParam = cch -//lParam = (LPARAM)(char*)pszVersion -//cch is the size of the buffer pointed to by pszVersion, in bytes -//may return a build qualifier, such as "0.1.0.1 alpha" -//returns 0 on success, nonzero on failure +// gets the version of Miranda encoded as text v0.1.0.1+ +// wParam = cch +// lParam = (LPARAM)(char*)pszVersion +// cch is the size of the buffer pointed to by pszVersion, in bytes +// may return a build qualifier, such as "0.1.0.1 alpha" +// returns 0 on success, nonzero on failure #define MS_SYSTEM_GETVERSIONTEXT "Miranda/System/GetVersionText" -//Adds a HANDLE to the list to be checked in the main message loop v0.1.2.0+ -//wParam = (WPARAM)(HANDLE)hObject -//lParam = (LPARAM)(const char*)pszService -//returns 0 on success or nonzero on failure -//Causes pszService to be CallService()d (wParam = hObject, lParam = 0) from the -//main thread whenever hObject is signalled. -//The Miranda message loop has a MsgWaitForMultipleObjects() call in it to -//implement this feature. See the documentation for that function for -//information on what objects are supported. -//There is a limit of MAXIMUM_WAIT_OBJECTS minus one (MWO is defined in winnt.h -//to be 64) on the number of handles MSFMO() can process. This service will -//return nonzero if that many handles are already being waited on. - -//As of writing, the following parts of Miranda are thread-safe, so can be -//called from any thread: -//All of modules.h except NotifyEventHooks() -//Read-only parts of m_database.h (since the write parts will call hooks) -//All of m_langpack.h -//for all other routines your mileage may vary, but I would strongly recommend -//that you call them from the main thread, or ask about it on plugin-dev if you -//think it really ought to work. - -//Update during 0.1.2.0 development, 16/10/01: -//NotifyEventHooks() now translates all calls into the context of the main -//thread, which means that all of m_database.h is now completely safe. - -//Update during 0.1.2.2 development, 17/4/02: -//The main thread's message loop now also deals with asynchronous procedure -//calls. Loop up QueueUserAPC() for a neater way to accomplish a lot of the -//things that used to require ms_system_waitonhandle. - -//Miranda is compiled with the multithreaded runtime - don't forget to do the -//same with your plugin. -#define MS_SYSTEM_WAITONHANDLE "Miranda/System/WaitOnHandle" - -//Removes a HANDLE from the wait list v0.1.2.0+ -//wParam = (WPARAM)(HANDLE)hObject -//lParam = 0 -//returns 0 on success or nonzero on failure. -#define MS_SYSTEM_REMOVEWAIT "Miranda/System/RemoveWait" +// Adds an event to the list to be checked in the main message loop +// when a handle gets triggered, an appopriate stub gets called + +typedef void (CALLBACK *MWaitableStub)(void); +MIR_APP_DLL(void) Miranda_WaitOnHandle(MWaitableStub pFunc, HANDLE hEvent = NULL); /* wParam = 0 diff --git a/plugins/CryptoPP/crypto/src/wait.cpp b/plugins/CryptoPP/crypto/src/wait.cpp index e4bae04faa..b031922638 100644 --- a/plugins/CryptoPP/crypto/src/wait.cpp +++ b/plugins/CryptoPP/crypto/src/wait.cpp @@ -13,6 +13,8 @@ #include #endif +#define MAXIMUM_WAIT_OBJECTS 64 + NAMESPACE_BEGIN(CryptoPP) unsigned int WaitObjectContainer::MaxWaitObjects() diff --git a/plugins/Sessions/Src/Main.cpp b/plugins/Sessions/Src/Main.cpp index d1c379893d..ba1cbaf64d 100644 --- a/plugins/Sessions/Src/Main.cpp +++ b/plugins/Sessions/Src/Main.cpp @@ -740,11 +740,8 @@ static int CreateButtons(WPARAM, LPARAM) return 0; } -static INT_PTR LaunchSessions(WPARAM wParam, LPARAM) +static void CALLBACK LaunchSessions() { - CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0); - CloseHandle((HANDLE)wParam); - int startup = db_get_b(NULL, MODNAME, "StartupMode", 3); if (startup == 1 || (startup == 3 && isLastTRUE == TRUE)) { StartUp = TRUE; @@ -754,7 +751,6 @@ static INT_PTR LaunchSessions(WPARAM wParam, LPARAM) g_hghostw = TRUE; g_hDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); } - return 0; } static int PluginInit(WPARAM, LPARAM) @@ -846,11 +842,7 @@ extern "C" __declspec(dllexport) int Load(void) CreateServiceFunction(MS_SESSIONS_SAVEUSERSESSION, SaveUserSessionHandles); CreateServiceFunction(MS_SESSIONS_CLOSESESSION, CloseCurrentSession); - HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); - if (hEvent != 0) { - CreateServiceFunction(MS_SESSIONS_LAUNCHME, LaunchSessions); - CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)MS_SESSIONS_LAUNCHME); - } + Miranda_WaitOnHandle(LaunchSessions); g_ses_count = db_get_b(NULL, MODNAME, "UserSessionsCount", 0); g_ses_limit = db_get_b(NULL, MODNAME, "TrackCount", 10); diff --git a/plugins/Sessions/Src/stdafx.h b/plugins/Sessions/Src/stdafx.h index d6cad97c92..35d25db35b 100644 --- a/plugins/Sessions/Src/stdafx.h +++ b/plugins/Sessions/Src/stdafx.h @@ -44,8 +44,6 @@ along with this program. If not, see . #define MODNAME "Sessions" -#define MS_SESSIONS_LAUNCHME "Sessions/Service/LaunchMe" - extern IconItem iconList[]; #define MIIM_STRING 0x00000040 diff --git a/plugins/TopToolBar/src/toolbar.cpp b/plugins/TopToolBar/src/toolbar.cpp index a8c037a7ac..ecb7db6de1 100644 --- a/plugins/TopToolBar/src/toolbar.cpp +++ b/plugins/TopToolBar/src/toolbar.cpp @@ -5,7 +5,7 @@ pfnCustomProc g_CustomProc = NULL; LPARAM g_CustomProcParam = 0; TTBCtrl *g_ctrl = NULL; -INT_PTR OnEventFire(WPARAM wParam, LPARAM lParam); +void CALLBACK OnEventFire(); HWND hwndContactList = 0; @@ -575,9 +575,7 @@ static int OnModulesLoad(WPARAM, LPARAM) ArrangeButtons(); - HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);//anonymous event - if (hEvent != 0) - CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)"TTB_ONSTARTUPFIRE"); + Miranda_WaitOnHandle(OnEventFire); if (HookEvent(ME_BACKGROUNDCONFIG_CHANGED, OnBGChange)) { char buf[256]; @@ -662,7 +660,6 @@ int LoadToolbarModule() CreateServiceFunction(TTB_LAUNCHSERVICE, LaunchService); CreateServiceFunction("TopToolBar/SetCustomProc", TTBSetCustomProc); - CreateServiceFunction("TTB_ONSTARTUPFIRE", OnEventFire); buttonWndProc = (WNDPROC)CallService("Button/GetWindowProc", 0, 0); WNDCLASSEX wc = {0}; diff --git a/plugins/TopToolBar/src/toolbarwnd.cpp b/plugins/TopToolBar/src/toolbarwnd.cpp index 8962a36af0..f02645e039 100644 --- a/plugins/TopToolBar/src/toolbarwnd.cpp +++ b/plugins/TopToolBar/src/toolbarwnd.cpp @@ -238,14 +238,11 @@ LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara ///////////////////////////////////////////////////////////////////////////////////////// -INT_PTR OnEventFire(WPARAM wParam, LPARAM) +void CALLBACK OnEventFire() { - CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0); - CloseHandle((HANDLE)wParam); - HWND parent = pcli->hwndContactList; if (parent == NULL) // no clist, no buttons - return -1; + return; WNDCLASS wndclass = {0}; wndclass.lpfnWndProc = TopToolBarProc; @@ -284,8 +281,6 @@ INT_PTR OnEventFire(WPARAM wParam, LPARAM) // receive buttons NotifyEventHooks(hTTBModuleLoaded, 0, 0); - - return 0; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -309,6 +304,5 @@ int LoadBackgroundOptions() GetClientRect(g_ctrl->hWnd, &rc); InvalidateRect(g_ctrl->hWnd, &rc, TRUE); UpdateWindow(g_ctrl->hWnd); - return 0; } diff --git a/plugins/Watrack/watrack.dpr b/plugins/Watrack/watrack.dpr index c1c947704a..478ced86a1 100644 --- a/plugins/Watrack/watrack.dpr +++ b/plugins/Watrack/watrack.dpr @@ -417,14 +417,10 @@ begin NotifyEventHooks(hHookWATStatus,WAT_EVENT_PLUGINSTATUS,DisablePlugin); end; -function WaitAllModules(wParam:WPARAM;lParam:LPARAM):int;cdecl; +procedure WaitAllModules; stdcall; var ptr:pwModule; begin - result:=0; - - CallService(MS_SYSTEM_REMOVEWAIT,wParam,0); - ptr:=ModuleLink; while ptr<>nil do begin @@ -439,7 +435,6 @@ begin StartTimer; NotifyEventHooks(hHookWATLoaded,0,0); - CloseHandle(hEvent); end; procedure DoTheDew(load:boolean); @@ -561,13 +556,7 @@ begin end; // Load WATrack modules - hEvent:=CreateEvent(nil,true,true,nil); - if hEvent<>0 then - begin - p:='WAT_INIT'; - CreateServiceFunction(p,@WaitAllModules); - CallService(MS_SYSTEM_WAITONHANDLE,hEvent,tlparam(p)); - end; + Miranda_WaitOnHandle(@WaitAllModules, 0); LoadOpt; if DisablePlugin=dsPermanent then diff --git a/protocols/MRA/src/MraAvatars.cpp b/protocols/MRA/src/MraAvatars.cpp index 4e4183c1f3..74c8009b29 100644 --- a/protocols/MRA/src/MraAvatars.cpp +++ b/protocols/MRA/src/MraAvatars.cpp @@ -19,7 +19,7 @@ const LPSTR lpcszContentType[9] = struct MRA_AVATARS_QUEUE : public FIFO_MT { HANDLE hNetlibUser; - HANDLE hThreadEvents[MAXIMUM_WAIT_OBJECTS]; + HANDLE hThreadEvents[64]; int iThreadsCount, iThreadsRunning; }; @@ -67,8 +67,8 @@ DWORD CMraProto::MraAvatarsQueueInitialize(HANDLE *phAvatarsQueueHandle) pmraaqAvatarsQueue->iThreadsCount = db_get_dw(NULL, MRA_AVT_SECT_NAME, "WorkThreadsCount", MRA_AVT_DEFAULT_WRK_THREAD_COUNTS); if (pmraaqAvatarsQueue->iThreadsCount == 0) pmraaqAvatarsQueue->iThreadsCount = 1; - if (pmraaqAvatarsQueue->iThreadsCount > MAXIMUM_WAIT_OBJECTS) - pmraaqAvatarsQueue->iThreadsCount = MAXIMUM_WAIT_OBJECTS; + if (pmraaqAvatarsQueue->iThreadsCount > 64) + pmraaqAvatarsQueue->iThreadsCount = 64; pmraaqAvatarsQueue->iThreadsRunning = 0; for (int i = 0; i < pmraaqAvatarsQueue->iThreadsCount; i++) diff --git a/protocols/Sametime/src/glib/gpoll.c b/protocols/Sametime/src/glib/gpoll.c index 940abae38f..e9410c7ded 100644 --- a/protocols/Sametime/src/glib/gpoll.c +++ b/protocols/Sametime/src/glib/gpoll.c @@ -261,7 +261,7 @@ g_poll (GPollFD *fds, guint nfds, gint timeout) { - HANDLE handles[MAXIMUM_WAIT_OBJECTS]; + HANDLE handles[64]; gboolean poll_msgs = FALSE; GPollFD *f; gint nhandles = 0; @@ -291,7 +291,7 @@ g_poll (GPollFD *fds, if (i == nhandles) { - if (nhandles == MAXIMUM_WAIT_OBJECTS) + if (nhandles == _countof(handles)) { g_warning ("Too many handles to wait for!\n"); break; diff --git a/src/mir_app/src/db_ini.cpp b/src/mir_app/src/db_ini.cpp index b33095de6c..7dd28b411b 100644 --- a/src/mir_app/src/db_ini.cpp +++ b/src/mir_app/src/db_ini.cpp @@ -593,11 +593,10 @@ static void DoAutoExec(void) FindClose(hFind); } -static INT_PTR CheckIniImportNow(WPARAM, LPARAM) +static void CALLBACK CheckIniImportNow() { DoAutoExec(); FindNextChangeNotification(hIniChangeNotification); - return 0; } static INT_PTR ImportINI(WPARAM wParam, LPARAM) @@ -616,10 +615,9 @@ int InitIni(void) wchar_t szMirandaDir[MAX_PATH]; PathToAbsoluteW(L".", szMirandaDir); hIniChangeNotification = FindFirstChangeNotification(szMirandaDir, 0, FILE_NOTIFY_CHANGE_FILE_NAME); - if (hIniChangeNotification != INVALID_HANDLE_VALUE) { - CreateServiceFunction("DB/Ini/CheckImportNow", CheckIniImportNow); - CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hIniChangeNotification, (LPARAM)"DB/Ini/CheckImportNow"); - } + if (hIniChangeNotification != INVALID_HANDLE_VALUE) + Miranda_WaitOnHandle(CheckIniImportNow, hIniChangeNotification); + return 0; } @@ -628,6 +626,5 @@ void UninitIni(void) if (!bModuleInitialized) return; - CallService(MS_SYSTEM_REMOVEWAIT, (WPARAM)hIniChangeNotification, 0); FindCloseChangeNotification(hIniChangeNotification); } diff --git a/src/mir_app/src/menu_utils.cpp b/src/mir_app/src/menu_utils.cpp index 2b2f07e35d..85b205ea19 100644 --- a/src/mir_app/src/menu_utils.cpp +++ b/src/mir_app/src/menu_utils.cpp @@ -916,11 +916,8 @@ static int sttDumpItem(TMO_IntMenuItem *pmi, void *szModule) return 0; } -static INT_PTR sttUpdateMenuService(WPARAM wParam, LPARAM) +static void CALLBACK sttUpdateMenuService() { - CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0); - CloseHandle((HANDLE)wParam); - for (int i = 0; i < g_menus.getCount(); i++) { TIntMenuObject *pmo = g_menus[i]; if (!pmo->m_bUseUserDefinedItems) @@ -963,16 +960,11 @@ static INT_PTR sttUpdateMenuService(WPARAM wParam, LPARAM) MO_RecursiveWalkMenu(pmo->m_items.first, Menu_LoadFromDatabase, szModule); } } - return 0; } -#define MS_MENU_UPDATE "System/Genmenu/Update" - void ScheduleMenuUpdate() { - HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); - CreateServiceFunction(MS_MENU_UPDATE, sttUpdateMenuService); - CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)MS_MENU_UPDATE); + Miranda_WaitOnHandle(sttUpdateMenuService); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 6cd5b0ddf1..2dcaf3ed1b 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -338,3 +338,4 @@ Srmm_RedrawToolbarIcons @338 Srmm_GetNthButton @339 Srmm_GetButtonCount @340 Srmm_ClickToolbarIcon @341 +Miranda_WaitOnHandle @342 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index b7ca0d8171..73b3111bf1 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -338,3 +338,4 @@ Srmm_RedrawToolbarIcons @338 Srmm_GetNthButton @339 Srmm_GetButtonCount @340 Srmm_ClickToolbarIcon @341 +Miranda_WaitOnHandle @342 diff --git a/src/mir_app/src/miranda.cpp b/src/mir_app/src/miranda.cpp index 6c6452066c..e21b06339e 100644 --- a/src/mir_app/src/miranda.cpp +++ b/src/mir_app/src/miranda.cpp @@ -42,13 +42,10 @@ pfnGetBufferedPaintBits getBufferedPaintBits; pfnDwmExtendFrameIntoClientArea dwmExtendFrameIntoClientArea; pfnDwmIsCompositionEnabled dwmIsCompositionEnabled; -ITaskbarList3 * pTaskbarInterface; +ITaskbarList3 *pTaskbarInterface; HANDLE hOkToExitEvent, hModulesLoadedEvent; HANDLE hShutdownEvent, hPreShutdownEvent; -static HANDLE hWaitObjects[MAXIMUM_WAIT_OBJECTS-1]; -static char *pszWaitServices[MAXIMUM_WAIT_OBJECTS-1]; -static int waitObjectCount = 0; HANDLE hMirandaShutdown; HINSTANCE g_hInst; DWORD hMainThreadId; @@ -56,6 +53,42 @@ int hLangpack = 0; bool bModulesLoadedFired = false; int g_iIconX, g_iIconY, g_iIconSX, g_iIconSY; +///////////////////////////////////////////////////////////////////////////////////////// + +struct MWaitableObject +{ + MWaitableObject(MWaitableStub pFunc, HANDLE hEvent) : + m_bOwnsEvent(false), + m_hEvent(hEvent), + m_pFunc(pFunc) + { + if (hEvent == NULL) { + m_hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); + m_bOwnsEvent = true; + } + } + + ~MWaitableObject() + { + if (m_bOwnsEvent) + ::CloseHandle(m_hEvent); + } + + bool m_bOwnsEvent; + HANDLE m_hEvent; + MWaitableStub m_pFunc; +}; + +static OBJLIST arWaitableObjects(1, HandleKeySortT); + +MIR_APP_DLL(void) Miranda_WaitOnHandle(MWaitableStub pFunc, HANDLE hEvent) +{ + arWaitableObjects.insert(new MWaitableObject(pFunc, hEvent)); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// dll entry point + BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID) { if (dwReason == DLL_PROCESS_ATTACH) { @@ -214,6 +247,15 @@ INT_PTR CheckRestart() static void crtErrorHandler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned, uintptr_t) {} +static DWORD myWait() +{ + HANDLE *hWaitObjects = (HANDLE*)_alloca(arWaitableObjects.getCount() * sizeof(HANDLE)); + for (int i = 0; i < arWaitableObjects.getCount(); i++) + hWaitObjects[i] = arWaitableObjects[i].m_hEvent; + + return MsgWaitForMultipleObjectsEx(arWaitableObjects.getCount(), hWaitObjects, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE); +} + int WINAPI mir_main(LPTSTR cmdLine) { hMainThreadId = GetCurrentThreadId(); @@ -286,12 +328,13 @@ int WINAPI mir_main(LPTSTR cmdLine) while (messageloop) { MSG msg; BOOL dying = FALSE; - DWORD rc = MsgWaitForMultipleObjectsEx(waitObjectCount, hWaitObjects, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE); - if (rc < WAIT_OBJECT_0 + waitObjectCount) { + DWORD rc = myWait(); + if (rc < WAIT_OBJECT_0 + arWaitableObjects.getCount()) { rc -= WAIT_OBJECT_0; - CallService(pszWaitServices[rc], (WPARAM)hWaitObjects[rc], 0); + (*arWaitableObjects[rc].m_pFunc)(); + arWaitableObjects.remove(rc); } - // + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message != WM_QUIT) { HWND h = GetForegroundWindow(); @@ -402,34 +445,6 @@ static INT_PTR GetMirandaVersionText(WPARAM wParam, LPARAM lParam) return 0; } -INT_PTR WaitOnHandle(WPARAM wParam, LPARAM lParam) -{ - if (waitObjectCount >= MAXIMUM_WAIT_OBJECTS - 1) - return 1; - - hWaitObjects[waitObjectCount] = (HANDLE)wParam; - pszWaitServices[waitObjectCount] = (char*)lParam; - waitObjectCount++; - return 0; -} - -static INT_PTR RemoveWait(WPARAM wParam, LPARAM) -{ - int i; - - for (i = 0; i < waitObjectCount; i++) - if (hWaitObjects[i] == (HANDLE)wParam) - break; - - if (i == waitObjectCount) - return 1; - - waitObjectCount--; - memmove(&hWaitObjects[i], &hWaitObjects[i + 1], sizeof(HANDLE)*(waitObjectCount - i)); - memmove(&pszWaitServices[i], &pszWaitServices[i + 1], sizeof(char*)*(waitObjectCount - i)); - return 0; -} - /////////////////////////////////////////////////////////////////////////////// int LoadSystemModule(void) @@ -446,8 +461,6 @@ int LoadSystemModule(void) CreateServiceFunction(MS_SYSTEM_GETVERSION, GetMirandaVersion); CreateServiceFunction(MS_SYSTEM_GETFILEVERSION, GetMirandaFileVersion); CreateServiceFunction(MS_SYSTEM_GETVERSIONTEXT, GetMirandaVersionText); - CreateServiceFunction(MS_SYSTEM_WAITONHANDLE, WaitOnHandle); - CreateServiceFunction(MS_SYSTEM_REMOVEWAIT, RemoveWait); CreateServiceFunction(MS_SYSTEM_GETEXCEPTFILTER, srvGetExceptionFilter); CreateServiceFunction(MS_SYSTEM_SETEXCEPTFILTER, srvSetExceptionFilter); return 0; diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp index 5c96538e40..caf9335836 100644 --- a/src/mir_app/src/srmm_toolbar.cpp +++ b/src/mir_app/src/srmm_toolbar.cpp @@ -741,13 +741,9 @@ static int SrmmModulesLoaded(WPARAM, LPARAM) return 0; } -static INT_PTR SrmmLoadToolbar(WPARAM wParam, LPARAM) +static void CALLBACK SrmmLoadToolbar() { - CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0); - CloseHandle((HANDLE)wParam); - NotifyEventHooks(hHookToolBarLoadedEvt, 0, 0); - return 0; } static int ConvertToolbarData(const char *szSetting, LPARAM) @@ -764,9 +760,7 @@ void LoadSrmmToolbarModule() { HookEvent(ME_SYSTEM_MODULESLOADED, SrmmModulesLoaded); - HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); - CreateServiceFunction("Srmm/LoadToolbar", SrmmLoadToolbar); - CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)"Srmm/LoadToolbar"); + Miranda_WaitOnHandle(SrmmLoadToolbar); hHookButtonPressedEvt = CreateHookableEvent(ME_MSG_BUTTONPRESSED); hHookToolBarLoadedEvt = CreateHookableEvent(ME_MSG_TOOLBARLOADED); -- cgit v1.2.3