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 | |
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')
-rw-r--r-- | protocols/IcqOscarJ/src/icq_proto.h | 2 | ||||
-rw-r--r-- | protocols/IcqOscarJ/src/icq_rates.cpp | 43 | ||||
-rw-r--r-- | protocols/IcqOscarJ/src/icq_rates.h | 9 |
3 files changed, 20 insertions, 34 deletions
diff --git a/protocols/IcqOscarJ/src/icq_proto.h b/protocols/IcqOscarJ/src/icq_proto.h index d879d64c3d..d1d8d677c8 100644 --- a/protocols/IcqOscarJ/src/icq_proto.h +++ b/protocols/IcqOscarJ/src/icq_proto.h @@ -532,8 +532,6 @@ struct CIcqProto : public PROTO<CIcqProto> int handleRateItem(rates_queue_item *item, int nQueueType = RQT_DEFAULT, int nMinDelay = 0, BOOL bAllowDelay = TRUE);
- void __cdecl rateDelayThread(struct rate_delay_args *pArgs);
-
//----| icq_server.cpp |--------------------------------------------------------------
HANDLE hServerConn;
WORD wListenPort;
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)
diff --git a/protocols/IcqOscarJ/src/icq_rates.h b/protocols/IcqOscarJ/src/icq_rates.h index c3c8f560f3..8cdc9243a0 100644 --- a/protocols/IcqOscarJ/src/icq_rates.h +++ b/protocols/IcqOscarJ/src/icq_rates.h @@ -115,9 +115,6 @@ public: char *szUid;
};
-class rates_queue;
-typedef void (rates_queue::*IcqRateFunc)(void);
-
//
// generic item queue (FIFO)
//
@@ -125,21 +122,23 @@ class rates_queue : public MZeroedObject {
CIcqProto *ppro;
const char *szDescr;
- int duplicates;
+ int duplicates;
+ int scheduledDelay;
mir_cs csLists; // we need to be thread safe
LIST<rates_queue_item> lstPending;
protected:
void cleanup();
+ void initDelay(int nDelay);
void processQueue();
- void initDelay(int nDelay, IcqRateFunc delaycode);
public:
rates_queue(CIcqProto *ppro, const char *szDescr, int nLimitLevel, int nWaitLevel, int nDuplicates);
~rates_queue();
void putItem(rates_queue_item *pItem, int nMinDelay);
+ void handleDelay();
int limitLevel; // RML_*
int waitLevel;
|