| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "CConcurrentHashModificationTester.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
CConcurrentHashModificationTester::CConcurrentHashModificationTester() { |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
CConcurrentHashModificationTester::~CConcurrentHashModificationTester() { |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
void CConcurrentHashModificationTester::generateTestingStructure(cint64 modificationThreadsCount, cint64 modificationCountPerStep, bool useModifiedHashes, bool extendBaseHashes) { |
| 39 |
mModificationThreadsCount = modificationThreadsCount; |
| 40 |
mModificationCountPerStep = modificationCountPerStep; |
| 41 |
mExtendBaseHashes = extendBaseHashes; |
| 42 |
|
| 43 |
cint64 initialFillCountMax = 100; |
| 44 |
cint64 initialFillCountMin = 50; |
| 45 |
cint64 maxCacheValue = 100; |
| 46 |
|
| 47 |
mHashesCount = 50; |
| 48 |
mMemoryPoolProvider = new CNewAllocationMemoryPoolProvider(1024*10-20 /*~ 10 KByte*/); |
| 49 |
mQtOriginalHashes = new CQtHash<cint64,cint64>*[mHashesCount]; |
| 50 |
mQtModifiedHashes = new CQtManagedRestrictedModificationHash<cint64,cint64>*[mHashesCount]; |
| 51 |
for (cint64 i = 0; i < mHashesCount; ++i) { |
| 52 |
CQtHash<cint64,cint64>* newQtOriginalHash = new CQtHash<cint64,cint64>(); |
| 53 |
mQtOriginalHashes[i] = newQtOriginalHash; |
| 54 |
mHashContainer1.append(newQtOriginalHash); |
| 55 |
CQtManagedRestrictedModificationHash<cint64,cint64>* newQtManagedMutHash = new CQtManagedRestrictedModificationHash<cint64,cint64>(); |
| 56 |
mQtModifiedHashes[i] = newQtManagedMutHash; |
| 57 |
mHashContainer2.append(newQtManagedMutHash); |
| 58 |
|
| 59 |
cint64 fillCount = (qrand() % (initialFillCountMax-initialFillCountMin))+initialFillCountMin; |
| 60 |
|
| 61 |
for (cint64 i = 0; i < fillCount; ++i) { |
| 62 |
qint64 modHashKey = qrand() % maxCacheValue; |
| 63 |
newQtOriginalHash->insert(modHashKey,i); |
| 64 |
newQtManagedMutHash->insert(modHashKey,i); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
for (qint64 i = 0; i < mModificationThreadsCount; ++i) { |
| 69 |
CHashModificationThread *modThread = 0; |
| 70 |
if (useModifiedHashes) { |
| 71 |
modThread = new CHashModificationThread(mQtModifiedHashes,mHashesCount,mMemoryPoolProvider,mModificationCountPerStep,mExtendBaseHashes); |
| 72 |
} else { |
| 73 |
modThread = new CHashModificationThread(mQtOriginalHashes,mHashesCount,mModificationCountPerStep,mExtendBaseHashes); |
| 74 |
} |
| 75 |
mModThreadList.append(modThread); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
void CConcurrentHashModificationTester::startHashModificationTest() { |
| 80 |
cForeach (CHashModificationThread* modThread, mModThreadList) { |
| 81 |
modThread->startModifications(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
void CConcurrentHashModificationTester::stopHashModificationTest() { |
| 86 |
cForeach (CHashModificationThread* modThread, mModThreadList) { |
| 87 |
modThread->stopModifications(); |
| 88 |
} |
| 89 |
cForeach (CHashModificationThread* modThread, mModThreadList) { |
| 90 |
modThread->quit(); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
void CConcurrentHashModificationTester::destroyTestingStructure() { |
| 95 |
cDeleteAll(mModThreadList); |
| 96 |
delete mMemoryPoolProvider; |
| 97 |
delete mQtOriginalHashes; |
| 98 |
delete mQtModifiedHashes; |
| 99 |
cDeleteAll(mHashContainer2); |
| 100 |
cDeleteAll(mHashContainer1); |
| 101 |
mHashContainer1.clear(); |
| 102 |
mHashContainer2.clear(); |
| 103 |
mModThreadList.clear(); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
cint64 CConcurrentHashModificationTester::getModificationStepsCount() { |
| 108 |
cint64 totalModStepsCount = 0; |
| 109 |
cForeach (CHashModificationThread* modThread, mModThreadList) { |
| 110 |
totalModStepsCount += modThread->getModificationStepsCount(); |
| 111 |
} |
| 112 |
return totalModStepsCount; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
}; // end namespace Test |
| 118 |
|
| 119 |
}; // end namespace Konclude |