diff options
author | George Hazan <george.hazan@gmail.com> | 2014-07-13 10:50:59 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-07-13 10:50:59 +0000 |
commit | 5df94ff719eccd04c7450df35fb5e3f2b36e2ee7 (patch) | |
tree | 440d736b199ff849ca0619adf355ffc73750ca7f /plugins/Scriver/src | |
parent | 70496fb739225b559a251f4518c946110aef718c (diff) |
wrapping the most evident critical sections into a class
git-svn-id: http://svn.miranda-ng.org/main/trunk@9785 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Scriver/src')
-rw-r--r-- | plugins/Scriver/src/richutil.cpp | 35 | ||||
-rw-r--r-- | plugins/Scriver/src/sendqueue.cpp | 38 | ||||
-rw-r--r-- | plugins/Scriver/src/sendqueue.h | 2 | ||||
-rw-r--r-- | plugins/Scriver/src/srmm.cpp | 2 |
4 files changed, 27 insertions, 50 deletions
diff --git a/plugins/Scriver/src/richutil.cpp b/plugins/Scriver/src/richutil.cpp index 9de434bc9e..7a338492ee 100644 --- a/plugins/Scriver/src/richutil.cpp +++ b/plugins/Scriver/src/richutil.cpp @@ -45,7 +45,7 @@ static int RichUtil_CmpVal(void *p1, void *p2) return (int)((INT_PTR)tp1->hwnd - (INT_PTR)tp2->hwnd);
}
-static CRITICAL_SECTION csRich;
+static mir_cs csRich;
static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static void RichUtil_ClearUglyBorder(TRichUtil *ru);
@@ -54,14 +54,11 @@ void RichUtil_Load(void) {
sListInt.increment = 10;
sListInt.sortFunc = RichUtil_CmpVal;
-
- InitializeCriticalSection(&csRich);
}
void RichUtil_Unload(void)
{
List_Destroy(&sListInt);
- DeleteCriticalSection(&csRich);
}
int RichUtil_SubClass(HWND hwndEdit)
@@ -73,12 +70,11 @@ int RichUtil_SubClass(HWND hwndEdit) ru->hwnd = hwndEdit;
ru->hasUglyBorder = 0;
-
- EnterCriticalSection(&csRich);
- if (!List_GetIndex(&sListInt, ru, &idx))
- List_Insert(&sListInt, ru, idx);
- LeaveCriticalSection(&csRich);
-
+ {
+ mir_cslock lck(csRich);
+ if (!List_GetIndex(&sListInt, ru, &idx))
+ List_Insert(&sListInt, ru, idx);
+ }
mir_subclassWindow(ru->hwnd, RichUtil_Proc);
RichUtil_ClearUglyBorder(ru);
return 1;
@@ -93,11 +89,11 @@ static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM LRESULT ret;
tru.hwnd = hwnd;
-
- EnterCriticalSection(&csRich);
- if (List_GetIndex(&sListInt, &tru, &idx))
- ru = (TRichUtil *)sListInt.items[idx];
- LeaveCriticalSection(&csRich);
+ {
+ mir_cslock lck(csRich);
+ if (List_GetIndex(&sListInt, &tru, &idx))
+ ru = (TRichUtil *)sListInt.items[idx];
+ }
switch (msg) {
case WM_THEMECHANGED:
@@ -182,11 +178,10 @@ static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case WM_NCDESTROY:
ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam);
-
- EnterCriticalSection(&csRich);
- List_Remove(&sListInt, idx);
- LeaveCriticalSection(&csRich);
-
+ {
+ mir_cslock lck(csRich);
+ List_Remove(&sListInt, idx);
+ }
mir_free(ru);
return ret;
}
diff --git a/plugins/Scriver/src/sendqueue.cpp b/plugins/Scriver/src/sendqueue.cpp index 6175c87d22..93deeff0e8 100644 --- a/plugins/Scriver/src/sendqueue.cpp +++ b/plugins/Scriver/src/sendqueue.cpp @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
static MessageSendQueueItem *global_sendQueue = NULL;
-static CRITICAL_SECTION queueMutex;
+static mir_cs queueMutex;
TCHAR * GetSendBufferMsg(MessageSendQueueItem *item)
{
@@ -41,42 +41,28 @@ TCHAR * GetSendBufferMsg(MessageSendQueueItem *item) return szMsg;
}
-void InitSendQueue()
-{
- InitializeCriticalSection(&queueMutex);
-}
-
-void DestroySendQueue()
-{
- DeleteCriticalSection(&queueMutex);
-}
-
MessageSendQueueItem* CreateSendQueueItem(HWND hwndSender)
{
- MessageSendQueueItem *item = (MessageSendQueueItem *) mir_alloc(sizeof(MessageSendQueueItem));
- EnterCriticalSection(&queueMutex);
- ZeroMemory(item, sizeof(MessageSendQueueItem));
+ MessageSendQueueItem *item = (MessageSendQueueItem*)mir_calloc(sizeof(MessageSendQueueItem));
+
+ mir_cslock lck(queueMutex);
item->hwndSender = hwndSender;
item->next = global_sendQueue;
- if (global_sendQueue != NULL) {
+ if (global_sendQueue != NULL)
global_sendQueue->prev = item;
- }
+
global_sendQueue = item;
- LeaveCriticalSection(&queueMutex);
return item;
}
MessageSendQueueItem* FindOldestPendingSendQueueItem(HWND hwndSender, MCONTACT hContact)
{
- MessageSendQueueItem *item, *found = NULL;
- EnterCriticalSection(&queueMutex);
- for (item = global_sendQueue; item != NULL; item = item->next) {
- if (item->hwndSender == hwndSender && item->hContact == hContact && item->hwndErrorDlg == NULL) {
- found = item;
- }
- }
- LeaveCriticalSection(&queueMutex);
- return found;
+ mir_cslock lck(queueMutex);
+ for (MessageSendQueueItem *item = global_sendQueue; item != NULL; item = item->next)
+ if (item->hwndSender == hwndSender && item->hContact == hContact && item->hwndErrorDlg == NULL)
+ return item;
+
+ return NULL;
}
MessageSendQueueItem* FindSendQueueItem(MCONTACT hContact, HANDLE hSendId)
diff --git a/plugins/Scriver/src/sendqueue.h b/plugins/Scriver/src/sendqueue.h index 688c7bd629..8445a2dbac 100644 --- a/plugins/Scriver/src/sendqueue.h +++ b/plugins/Scriver/src/sendqueue.h @@ -40,8 +40,6 @@ struct MessageSendQueueItem MessageSendQueueItem *prev, *next;
};
-void InitSendQueue();
-void DestroySendQueue();
MessageSendQueueItem* CreateSendQueueItem(HWND hwndSender);
TCHAR * GetSendBufferMsg(MessageSendQueueItem *item);
MessageSendQueueItem* FindOldestPendingSendQueueItem(HWND hwndSender, MCONTACT hContact);
diff --git a/plugins/Scriver/src/srmm.cpp b/plugins/Scriver/src/srmm.cpp index 2bfa95c935..4dd628a6f8 100644 --- a/plugins/Scriver/src/srmm.cpp +++ b/plugins/Scriver/src/srmm.cpp @@ -70,13 +70,11 @@ extern "C" __declspec(dllexport) int Load(void) if (IsWinVer7Plus())
CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_ALL, IID_ITaskbarList3, (void**)&pTaskbarInterface);
- InitSendQueue();
return OnLoadModule();
}
extern "C" __declspec(dllexport) int Unload(void)
{
- DestroySendQueue();
if (pTaskbarInterface)
pTaskbarInterface->Release();
return OnUnloadModule();
|