From 4b4c9d139f15b208cd0f0008d2bf81f21d462232 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 12 Mar 2019 12:40:25 +0300 Subject: another manual critical section removed --- src/mir_core/src/miranda.h | 6 +++--- src/mir_core/src/modules.cpp | 13 +++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/mir_core/src/miranda.h b/src/mir_core/src/miranda.h index bd83beeea1..a62d879270 100644 --- a/src/mir_core/src/miranda.h +++ b/src/mir_core/src/miranda.h @@ -64,15 +64,15 @@ struct THookSubscriber #define HOOK_SECRET_SIGNATURE 0xDEADBABA -struct THook +struct THook : public MZeroedObject { char name[ MAXMODULELABELLENGTH ]; int id; int subscriberCount; THookSubscriber* subscriber; MIRANDAHOOK pfnHook; - DWORD secretSignature; - CRITICAL_SECTION csHook; + DWORD secretSignature = HOOK_SECRET_SIGNATURE; + mir_cs csHook; }; extern LIST pluginListAddr; diff --git a/src/mir_core/src/modules.cpp b/src/mir_core/src/modules.cpp index d73b8124b7..fa900e7832 100644 --- a/src/mir_core/src/modules.cpp +++ b/src/mir_core/src/modules.cpp @@ -114,14 +114,9 @@ MIR_CORE_DLL(HANDLE) CreateHookableEvent(const char *name) if ((idx = hooks.getIndex((THook*)name)) != -1) return hooks[idx]; - THook *newItem = (THook*)mir_alloc(sizeof(THook)); + THook *newItem = new THook(); strncpy(newItem->name, name, sizeof(newItem->name)); newItem->name[MAXMODULELABELLENGTH - 1] = 0; newItem->id = sttHookId++; - newItem->subscriberCount = 0; - newItem->subscriber = nullptr; - newItem->pfnHook = nullptr; - newItem->secretSignature = HOOK_SECRET_SIGNATURE; - InitializeCriticalSection(&newItem->csHook); hooks.insert(newItem); return (HANDLE)newItem; } @@ -145,8 +140,7 @@ MIR_CORE_DLL(int) DestroyHookableEvent(HANDLE hEvent) p->subscriberCount = 0; } hooks.remove(idx); - DeleteCriticalSection(&p->csHook); - mir_free(p); + delete p; return 0; } @@ -483,8 +477,7 @@ static void DestroyHooks() for (auto &it : hooks) { if (it->subscriberCount) mir_free(it->subscriber); - DeleteCriticalSection(&it->csHook); - mir_free(it); + delete it; } } -- cgit v1.2.3