32 #include "../StdAfx.h"
33 #ifndef ONLY_LOCAL_PROXY
36 #include "../CAUtil.hpp"
41 for (
UINT32 i = 0; i < 0x10000; i++) {
48 m_initialBucketSize = DELAY_CHANNEL_TRAFFIC;
49 m_delayBucketGrow = DELAY_BUCKET_GROW;
50 m_delayBucketGrowInterval = DELAY_BUCKET_GROW_INTERVALL;
51 m_pDelayBucketMutex =
new CAMutex();
54 m_pDelayBuckets[i] = -1;
57 m_delayBucketsLoopRun =
true;
58 m_pDelayBucketsLoop =
new CAThread((
UINT8*)
"CAChainTable: delay-buckets refill thread");
59 m_pDelayBucketsLoop->setMainLoop(lml_chaintableDelayBucketsLoop);
60 m_pDelayBucketsLoop->start(
this);
76 m_delayBucketsLoopRun =
false;
78 m_pDelayBucketsLoop->join();
79 delete m_pDelayBucketsLoop;
80 m_pDelayBucketsLoop = NULL;
81 delete m_pDelayBucketMutex;
82 m_pDelayBucketMutex = NULL;
83 delete []m_pDelayBuckets;
84 m_pDelayBuckets = NULL;
96 if (chaintableEntry != NULL) {
97 returnedChain = chaintableEntry->
chain;
100 return returnedChain;
106 if (chaintableEntry != NULL) {
193 #ifndef DELAY_CHANNELS
197 m_pDelayBucketMutex->lock();
199 bool bucketFound =
false;
201 if (m_pDelayBuckets[i] == -1) {
212 m_pDelayBucketMutex->unlock();
221 m_pDelayBuckets[i] = (
SINT32)m_initialBucketSize;
222 m_pDelayBucketMutex->unlock();
236 return (newEntry->
chain);
244 return chaintableSize;
252 bool entryFound =
false;
254 while ((currentEntry != NULL) && !entryFound) {
258 bool entryVirtualRemoved =
false;
261 entryVirtualRemoved =
true;
266 if (!entryVirtualRemoved) {
289 delete a_entry->
chain;
290 a_entry->
chain = NULL;
311 if (nextEntry == NULL) {
331 #ifdef DELAY_CHANNELS
332 THREAD_RETURN lml_chaintableDelayBucketsLoop(
void* a_param) {
335 while (pChainTable->m_delayBucketsLoopRun) {
336 pChainTable->m_pDelayBucketMutex->lock();
337 SINT32 bucketGrow = (
SINT32)(pChainTable->m_delayBucketGrow);
339 if ((pChainTable->m_pDelayBuckets[i]) != -1) {
341 pChainTable->m_pDelayBuckets[i] =
min((pChainTable->m_pDelayBuckets[i]) + bucketGrow, MAX_DELAY_BUCKET_SIZE);
344 pChainTable->m_pDelayBucketMutex->unlock();
351 void CAChainTable::setDelayParameters(
UINT32 a_initialBucketSize,
UINT32 a_delayBucketGrow,
UINT32 a_delayBucketGrowInterval) {
352 CAMsg::printMsg(LOG_DEBUG,
"CAChainTable - Set new traffic limit per channel: inital size: %u bucket grow: %u interval: %u\n", a_initialBucketSize, a_delayBucketGrow, a_delayBucketGrowInterval);
353 m_pDelayBucketMutex->lock();
354 m_initialBucketSize = a_initialBucketSize;
355 m_delayBucketGrow = a_delayBucketGrow;
356 m_delayBucketGrowInterval = a_delayBucketGrowInterval;
359 if (m_pDelayBuckets[i] != -1) {
361 m_pDelayBuckets[i] = a_initialBucketSize;
364 m_pDelayBucketMutex->unlock();
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
#define THREAD_RETURN_SUCCESS
t_chaintableIterator * m_pChaintableIterator
CAChain * getFirstEntry()
CAChain * getEntry(UINT8 *a_chainId)
void getNextEntryInternal(t_chaintableIterator *a_iterator)
t_chaintableEntry ** m_pChainTable
t_chaintableEntry * getEntryInternal(UINT8 *a_chainId)
void removeEntryInternal(t_chaintableEntry *a_entry)
void deleteEntry(UINT8 *a_chainId)
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
t_chaintableEntry * rightEntry
t_chaintableEntry ** rightEntryPointerOfLeftEntry
t_chaintableEntry * currentEntry
UINT8 chainId[CHAIN_ID_LENGTH]