diff options
author | George Hazan <george.hazan@gmail.com> | 2013-03-21 18:36:10 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-03-21 18:36:10 +0000 |
commit | 01b1b443b89cdff245c23c03af37718c7d0c90cd (patch) | |
tree | 2f058638ff8890cddf46373ef2cd624962fadc84 /protocols | |
parent | 530ca4410d99e166f4bbf1d6ba23e348a53d4743 (diff) |
fix for closing thread handles in MRA
git-svn-id: http://svn.miranda-ng.org/main/trunk@4152 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/MRA/src/MraAvatars.cpp | 18 | ||||
-rw-r--r-- | protocols/MRA/src/MraProto.cpp | 1 | ||||
-rw-r--r-- | protocols/MRA/src/Mra_proto.cpp | 5 |
3 files changed, 15 insertions, 9 deletions
diff --git a/protocols/MRA/src/MraAvatars.cpp b/protocols/MRA/src/MraAvatars.cpp index 2fb7581f0c..949395eb0a 100644 --- a/protocols/MRA/src/MraAvatars.cpp +++ b/protocols/MRA/src/MraAvatars.cpp @@ -33,7 +33,7 @@ struct MRA_AVATARS_QUEUE : public FIFO_MT BOOL bIsRunning;
HANDLE hNetlibUser;
HANDLE hThreadEvent;
- DWORD dwThreadsCount;
+ int iThreadsCount;
HANDLE hThread[MAXIMUM_WAIT_OBJECTS];
LONG lThreadsRunningCount;
HANDLE hAvatarsPath;
@@ -94,12 +94,12 @@ DWORD CMraProto::MraAvatarsQueueInitialize(HANDLE *phAvatarsQueueHandle) InterlockedExchange((volatile LONG*)&pmraaqAvatarsQueue->bIsRunning, TRUE);
pmraaqAvatarsQueue->hThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- pmraaqAvatarsQueue->dwThreadsCount = DBGetContactSettingDword(NULL, MRA_AVT_SECT_NAME, "WorkThreadsCount", MRA_AVT_DEFAULT_WRK_THREAD_COUNTS);
- if (pmraaqAvatarsQueue->dwThreadsCount == 0)
- pmraaqAvatarsQueue->dwThreadsCount = 1;
- if (pmraaqAvatarsQueue->dwThreadsCount > MAXIMUM_WAIT_OBJECTS)
- pmraaqAvatarsQueue->dwThreadsCount = MAXIMUM_WAIT_OBJECTS;
- for (DWORD i = 0; i < pmraaqAvatarsQueue->dwThreadsCount; i++)
+ pmraaqAvatarsQueue->iThreadsCount = DBGetContactSettingDword(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;
+ for (int i=0; i < pmraaqAvatarsQueue->iThreadsCount; i++)
pmraaqAvatarsQueue->hThread[i] = ForkThreadEx(&CMraProto::MraAvatarsThreadProc, pmraaqAvatarsQueue);
*phAvatarsQueueHandle = (HANDLE)pmraaqAvatarsQueue;
@@ -138,12 +138,14 @@ void CMraProto::MraAvatarsQueueDestroy(HANDLE hAvatarsQueueHandle) InterlockedExchange((volatile LONG*)&pmraaqAvatarsQueue->bIsRunning, FALSE);
SetEvent(pmraaqAvatarsQueue->hThreadEvent);
- WaitForMultipleObjects(pmraaqAvatarsQueue->dwThreadsCount, (HANDLE*)&pmraaqAvatarsQueue->hThread[0], TRUE, (WAIT_FOR_THREAD_TIMEOUT*1000));
+ WaitForMultipleObjects(pmraaqAvatarsQueue->iThreadsCount, (HANDLE*)&pmraaqAvatarsQueue->hThread[0], TRUE, (WAIT_FOR_THREAD_TIMEOUT*1000));
if (InterlockedExchangeAdd((volatile LONG*)&pmraaqAvatarsQueue->lThreadsRunningCount, 0))
while (InterlockedExchangeAdd((volatile LONG*)&pmraaqAvatarsQueue->lThreadsRunningCount, 0))
SleepEx(100, TRUE);
+ for (int i=0; i < pmraaqAvatarsQueue->iThreadsCount; i++)
+ CloseHandle(pmraaqAvatarsQueue->hThread[i]);
CloseHandle(pmraaqAvatarsQueue->hThreadEvent);
MraAvatarsQueueClear(hAvatarsQueueHandle);
diff --git a/protocols/MRA/src/MraProto.cpp b/protocols/MRA/src/MraProto.cpp index 1afc9c122a..6c7066bc3f 100644 --- a/protocols/MRA/src/MraProto.cpp +++ b/protocols/MRA/src/MraProto.cpp @@ -136,6 +136,7 @@ int CMraProto::OnPreShutdown(WPARAM, LPARAM) if (hThreadWorker) {
if (IsThreadAlive(hThreadWorker))
WaitForSingleObjectEx(hThreadWorker, (WAIT_FOR_THREAD_TIMEOUT*1000), FALSE);
+ CloseHandle(hThreadWorker);
hThreadWorker = NULL;
}
diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp index fb441ea976..ea501f1dcd 100644 --- a/protocols/MRA/src/Mra_proto.cpp +++ b/protocols/MRA/src/Mra_proto.cpp @@ -123,7 +123,10 @@ void CMraProto::MraThreadClean() SleepEx(100, FALSE);// to prevent high CPU load by some status plugins like allwaysonline
- hThreadWorker = NULL;
+ if (hThreadWorker) {
+ CloseHandle(hThreadWorker);
+ hThreadWorker = NULL;
+ }
InterlockedExchange((volatile LONG*)&dwThreadWorkerRunning, FALSE);
SetStatus(ID_STATUS_OFFLINE);
}
|