summaryrefslogtreecommitdiff
path: root/protocols/MRA
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/MRA')
-rw-r--r--protocols/MRA/src/MraAvatars.cpp18
-rw-r--r--protocols/MRA/src/MraProto.cpp1
-rw-r--r--protocols/MRA/src/Mra_proto.cpp5
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);
}