Debian Codegraph @

Source/Test/CConcurrentMemoryAccessTester.cpp

raw
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 "CConcurrentMemoryAccessTester.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28
29
30 CConcurrentMemoryAccessTester::CConcurrentMemoryAccessTester() {
31 }
32
33
34 CConcurrentMemoryAccessTester::~CConcurrentMemoryAccessTester() {
35 }
36
37
38 void CConcurrentMemoryAccessTester::generateTestingStructure(cint64 arraySize, cint64 readWriteRatio, bool atomicOperations, cint64 threadCount) {
39 mArraySize = arraySize;
40 mReadWriteRatio = readWriteRatio;
41 mThreadCount = threadCount;
42 mAtomicOperations = atomicOperations;
43
44 mMemoryPoolProvider = new CNewAllocationMemoryPoolProvider(1024*10-20 /*~ 10 KByte*/);
45
46 mMemoryArray = new int[mArraySize];
47
48 mSharedWrite = false;
49
50 cint64 threadSize = arraySize / mThreadCount;
51 cint64 nextStart = 0;
52
53 if (mSharedWrite) {
54 threadSize = mThreadCount;
55 }
56
57 for (qint64 i = 0; i < mThreadCount; ++i) {
58 CMemoryAccessThread *modThread = 0;
59 modThread = new CMemoryAccessThread(mReadWriteRatio,mMemoryArray,mArraySize,mAtomicOperations,nextStart,nextStart+threadSize,mMemoryPoolProvider);
60 if (!mSharedWrite) {
61 nextStart += threadSize;
62 }
63 mModThreadList.append(modThread);
64 }
65 }
66
67 void CConcurrentMemoryAccessTester::startHashModificationTest() {
68 cForeach (CMemoryAccessThread* modThread, mModThreadList) {
69 modThread->startModifications();
70 }
71 }
72
73 void CConcurrentMemoryAccessTester::stopHashModificationTest() {
74 cForeach (CMemoryAccessThread* modThread, mModThreadList) {
75 modThread->stopModifications();
76 }
77 cForeach (CMemoryAccessThread* modThread, mModThreadList) {
78 modThread->quit();
79 }
80 }
81
82 void CConcurrentMemoryAccessTester::destroyTestingStructure() {
83 cDeleteAll(mModThreadList);
84 delete mMemoryPoolProvider;
85 delete [] mMemoryArray;
86 mModThreadList.clear();
87 }
88
89
90 cint64 CConcurrentMemoryAccessTester::getModificationStepsCount() {
91 cint64 totalModStepsCount = 0;
92 cForeach (CMemoryAccessThread* modThread, mModThreadList) {
93 totalModStepsCount += modThread->getModificationStepsCount();
94 }
95 return totalModStepsCount;
96 }
97
98
99
100 }; // end namespace Test
101
102 }; // end namespace Konclude