diff options
author | George Hazan <george.hazan@gmail.com> | 2015-06-30 10:04:37 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-06-30 10:04:37 +0000 |
commit | 7cf2491c1a67e31eb8765526d78b1bd4baf6f709 (patch) | |
tree | 32b43210d6d0e8b7e342f36260f4eb85f26c7614 /protocols/IcqOscarJ/src/icq_rates.cpp | |
parent | d2843de0f8ceebeeb87806bb9670d69f1218619b (diff) |
icq rates - code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@14451 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/IcqOscarJ/src/icq_rates.cpp')
-rw-r--r-- | protocols/IcqOscarJ/src/icq_rates.cpp | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/protocols/IcqOscarJ/src/icq_rates.cpp b/protocols/IcqOscarJ/src/icq_rates.cpp index 32fa47d0a1..b0e7d20b57 100644 --- a/protocols/IcqOscarJ/src/icq_rates.cpp +++ b/protocols/IcqOscarJ/src/icq_rates.cpp @@ -299,35 +299,26 @@ rates_queue::~rates_queue() cleanup();
}
-// links to functions that are under Rate Control
-struct rate_delay_args
+static void rateDelayThread(void *param)
{
- int nDelay;
- rates_queue *queue;
- IcqRateFunc delaycode;
-};
+ rates_queue *pQueue = (rates_queue*)param;
+ pQueue->handleDelay();
+}
-void __cdecl CIcqProto::rateDelayThread(rate_delay_args *pArgs)
+void rates_queue::initDelay(int nDelay)
{
- SleepEx(pArgs->nDelay, TRUE);
-
- if (g_bTerminated)
- return;
+ ppro->debugLogA("Rates: Delay %dms", nDelay);
- (pArgs->queue->*pArgs->delaycode)();
- SAFE_FREE((void**)&pArgs);
+ scheduledDelay = nDelay;
+ mir_forkthread(rateDelayThread, this);
}
-void rates_queue::initDelay(int nDelay, IcqRateFunc delaycode)
+void rates_queue::handleDelay()
{
- ppro->debugLogA("Rates: Delay %dms", nDelay);
-
- rate_delay_args *pArgs = (rate_delay_args*)SAFE_MALLOC(sizeof(rate_delay_args)); // This will be freed in the new thread
- pArgs->queue = this;
- pArgs->nDelay = nDelay;
- pArgs->delaycode = delaycode;
+ SleepEx(scheduledDelay, TRUE);
- ppro->ForkThread((CIcqProto::MyThreadFunc)&CIcqProto::rateDelayThread, pArgs);
+ if (!g_bTerminated)
+ processQueue();
}
void rates_queue::cleanup()
@@ -340,10 +331,8 @@ void rates_queue::cleanup() void rates_queue::processQueue()
{
- if (!ppro->icqOnline()) {
- cleanup();
+ if (!ppro->icqOnline())
return;
- }
// take from queue, execute
mir_cslockfull l(csLists);
@@ -359,7 +348,7 @@ void rates_queue::processQueue() l.unlock();
rlck.unlock();
if (nDelay < 10) nDelay = 10;
- initDelay(nDelay, &rates_queue::processQueue);
+ initDelay(nDelay);
return;
}
}
@@ -383,7 +372,7 @@ void rates_queue::processQueue() }
if (nDelay < 10) nDelay = 10;
- initDelay(nDelay, &rates_queue::processQueue);
+ initDelay(nDelay);
}
delete item;
}
@@ -424,7 +413,7 @@ void rates_queue::putItem(rates_queue_item *pItem, int nMinDelay) if (nDelay < 10) nDelay = 10;
if (nDelay < nMinDelay) nDelay = nMinDelay;
- initDelay(nDelay, &rates_queue::processQueue);
+ initDelay(nDelay);
}
int CIcqProto::handleRateItem(rates_queue_item *item, int nQueueType, int nMinDelay, BOOL bAllowDelay)
|