perfect: Rename functions name

This commit is contained in:
Calcitem 2021-01-20 01:22:17 +08:00
parent 4761897750
commit cc80e84dbe
10 changed files with 74 additions and 74 deletions

View File

@ -36,8 +36,8 @@ CyclicArray::CyclicArray(unsigned int blockSizeInBytes, unsigned int numberOfBlo
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: ~randomAI() // Name: ~RandomAI()
// Desc: randomAI class destructor // Desc: RandomAI class destructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CyclicArray::~CyclicArray() CyclicArray::~CyclicArray()
{ {

View File

@ -455,7 +455,7 @@ private:
}; };
}; };
struct InitAlphaBetaVars : public threadManagerClass::threadVarsArrayItem, public AlphaBetaDefaultThreadVars struct InitAlphaBetaVars : public ThreadManager::ThreadVarsArrayItem, public AlphaBetaDefaultThreadVars
{ {
BufferedFile *bufferedFile; BufferedFile *bufferedFile;
bool initAlreadyDone; bool initAlreadyDone;
@ -478,7 +478,7 @@ private:
}; };
}; };
struct RunAlphaBetaVars : public threadManagerClass::threadVarsArrayItem, public AlphaBetaDefaultThreadVars struct RunAlphaBetaVars : public ThreadManager::ThreadVarsArrayItem, public AlphaBetaDefaultThreadVars
{ {
Node *branchArray = nullptr; // array of size [(depthOfFullTree - tilLevel) * maxNumBranches] for storage of the branches at each search depth Node *branchArray = nullptr; // array of size [(depthOfFullTree - tilLevel) * maxNumBranches] for storage of the branches at each search depth
unsigned int *freqValuesSubMovesBranchWon = nullptr; // ... unsigned int *freqValuesSubMovesBranchWon = nullptr; // ...
@ -565,7 +565,7 @@ private:
}; };
}; };
struct InitRetroAnalysisVars : public threadManagerClass::threadVarsArrayItem, public RetroAnalysisDefaultThreadVars struct InitRetroAnalysisVars : public ThreadManager::ThreadVarsArrayItem, public RetroAnalysisDefaultThreadVars
{ {
BufferedFile *bufferedFile; BufferedFile *bufferedFile;
bool initAlreadyDone; bool initAlreadyDone;
@ -588,7 +588,7 @@ private:
}; };
}; };
struct AddNumSuccedorsVars : public threadManagerClass::threadVarsArrayItem, public RetroAnalysisDefaultThreadVars struct AddNumSuccedorsVars : public ThreadManager::ThreadVarsArrayItem, public RetroAnalysisDefaultThreadVars
{ {
RetroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS]; RetroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS];
@ -625,7 +625,7 @@ private:
vector<unsigned int> layersToCalculate; // used in calcLayer() and getCurrentCalculatedLayers() vector<unsigned int> layersToCalculate; // used in calcLayer() and getCurrentCalculatedLayers()
bool onlyPrepareLayer = false; // bool onlyPrepareLayer = false; //
bool stopOnCriticalError = true; // if true then process will stay in while loop bool stopOnCriticalError = true; // if true then process will stay in while loop
threadManagerClass threadManager; // ThreadManager threadManager; //
CRITICAL_SECTION csDatabase; // CRITICAL_SECTION csDatabase; //
CRITICAL_SECTION csOsPrint; // for thread safety when output is passed to osPrint CRITICAL_SECTION csOsPrint; // for thread safety when output is passed to osPrint
void (*userPrintFunc)(void *) = nullptr; // called every time output is passed to osPrint void (*userPrintFunc)(void *) = nullptr; // called every time output is passed to osPrint

View File

@ -111,7 +111,7 @@ bool MiniMax::initAlphaBeta(AlphaBetaGlobalVars &alphaBetaVars)
alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0;
alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0;
alphaBetaVars.statsValueCounter[SKV_VALUE_INVALID] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_INVALID] = 0;
threadManagerClass::threadVarsArray<InitAlphaBetaVars> tva(threadManager.getNumThreads(), InitAlphaBetaVars(this, &alphaBetaVars, alphaBetaVars.layerNumber, invalidArray, initAlreadyDone)); ThreadManager::ThreadVarsArray<InitAlphaBetaVars> tva(threadManager.getNumThreads(), InitAlphaBetaVars(this, &alphaBetaVars, alphaBetaVars.layerNumber, invalidArray, initAlreadyDone));
// process each state in the current layer // process each state in the current layer
switch (threadManager.executeParallelLoop(initAlphaBetaThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[alphaBetaVars.layerNumber].knotsInLayer - 1, 1)) { switch (threadManager.executeParallelLoop(initAlphaBetaThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[alphaBetaVars.layerNumber].knotsInLayer - 1, 1)) {
@ -228,7 +228,7 @@ bool MiniMax::runAlphaBeta(AlphaBetaGlobalVars &alphaBetaVars)
alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0;
alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0;
alphaBetaVars.statsValueCounter[SKV_VALUE_INVALID] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_INVALID] = 0;
threadManagerClass::threadVarsArray<RunAlphaBetaVars> tva(threadManager.getNumThreads(), RunAlphaBetaVars(this, &alphaBetaVars, alphaBetaVars.layerNumber)); ThreadManager::ThreadVarsArray<RunAlphaBetaVars> tva(threadManager.getNumThreads(), RunAlphaBetaVars(this, &alphaBetaVars, alphaBetaVars.layerNumber));
// so far no multi-threadin implemented // so far no multi-threadin implemented
threadManager.setNumThreads(1); threadManager.setNumThreads(1);

View File

@ -145,7 +145,7 @@ bool MiniMax::initRetroAnalysis(retroAnalysisGlobalVars &retroVars)
retroVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0; retroVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0;
retroVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0; retroVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0;
retroVars.statsValueCounter[SKV_VALUE_INVALID] = 0; retroVars.statsValueCounter[SKV_VALUE_INVALID] = 0;
threadManagerClass::threadVarsArray<InitRetroAnalysisVars> tva(threadManager.getNumThreads(), InitRetroAnalysisVars(this, &retroVars, layerNumber, initArray, initAlreadyDone)); ThreadManager::ThreadVarsArray<InitRetroAnalysisVars> tva(threadManager.getNumThreads(), InitRetroAnalysisVars(this, &retroVars, layerNumber, initArray, initAlreadyDone));
// process each state in the current layer // process each state in the current layer
switch (threadManager.executeParallelLoop(initRetroAnalysisThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[layerNumber].knotsInLayer - 1, 1)) { switch (threadManager.executeParallelLoop(initRetroAnalysisThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[layerNumber].knotsInLayer - 1, 1)) {
@ -360,7 +360,7 @@ bool MiniMax::calcNumSuccedors(retroAnalysisGlobalVars &retroVars)
// prepare parameters for multithreading // prepare parameters for multithreading
succCalculated[layerNumber] = true; succCalculated[layerNumber] = true;
numStatesProcessed = 0; numStatesProcessed = 0;
threadManagerClass::threadVarsArray<AddNumSuccedorsVars> tva(threadManager.getNumThreads(), AddNumSuccedorsVars(this, &retroVars, layerNumber)); ThreadManager::ThreadVarsArray<AddNumSuccedorsVars> tva(threadManager.getNumThreads(), AddNumSuccedorsVars(this, &retroVars, layerNumber));
// process each state in the current layer // process each state in the current layer
switch (threadManager.executeParallelLoop(addNumSuccedorsThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[layerNumber].knotsInLayer - 1, 1)) { switch (threadManager.executeParallelLoop(addNumSuccedorsThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[layerNumber].knotsInLayer - 1, 1)) {
@ -402,7 +402,7 @@ bool MiniMax::calcNumSuccedors(retroAnalysisGlobalVars &retroVars)
// prepare parameters for multithreading // prepare parameters for multithreading
numStatesProcessed = 0; numStatesProcessed = 0;
threadManagerClass::threadVarsArray<AddNumSuccedorsVars> tva(threadManager.getNumThreads(), AddNumSuccedorsVars(this, &retroVars, succState.layerNumber)); ThreadManager::ThreadVarsArray<AddNumSuccedorsVars> tva(threadManager.getNumThreads(), AddNumSuccedorsVars(this, &retroVars, succState.layerNumber));
// process each state in the current layer // process each state in the current layer
switch (threadManager.executeParallelLoop(addNumSuccedorsThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[succState.layerNumber].knotsInLayer - 1, 1)) { switch (threadManager.executeParallelLoop(addNumSuccedorsThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[succState.layerNumber].knotsInLayer - 1, 1)) {

View File

@ -1,5 +1,5 @@
/********************************************************************* /*********************************************************************
randomAI.cpp RandomAI.cpp
Copyright (c) Thomas Weber. All rights reserved. Copyright (c) Thomas Weber. All rights reserved.
Copyright (C) 2021 The Sanmill developers (see AUTHORS file) Copyright (C) 2021 The Sanmill developers (see AUTHORS file)
Licensed under the MIT License. Licensed under the MIT License.
@ -9,20 +9,20 @@
#include "randomAI.h" #include "randomAI.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: randomAI() // Name: RandomAI()
// Desc: randomAI class constructor // Desc: RandomAI class constructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
randomAI::randomAI() RandomAI::RandomAI()
{ {
// Init // Init
srand((unsigned)time(nullptr)); srand((unsigned)time(nullptr));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: ~randomAI() // Name: ~RandomAI()
// Desc: randomAI class destructor // Desc: RandomAI class destructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
randomAI::~randomAI() RandomAI::~RandomAI()
{ {
// Locals // Locals
@ -32,7 +32,7 @@ randomAI::~randomAI()
// Name: play() // Name: play()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void randomAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo) void RandomAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo)
{ {
// locals // locals
unsigned int from, to, direction; unsigned int from, to, direction;

View File

@ -1,5 +1,5 @@
/*********************************************************************\ /*********************************************************************\
randomAI.h RandomAI.h
Copyright (c) Thomas Weber. All rights reserved. Copyright (c) Thomas Weber. All rights reserved.
Copyright (C) 2021 The Sanmill developers (see AUTHORS file) Copyright (C) 2021 The Sanmill developers (see AUTHORS file)
Licensed under the MIT License. Licensed under the MIT License.
@ -15,12 +15,12 @@
/*** Klassen *********************************************************/ /*** Klassen *********************************************************/
class randomAI : public MillAI class RandomAI : public MillAI
{ {
public: public:
// Constructor / destructor // Constructor / destructor
randomAI(); RandomAI();
~randomAI(); ~RandomAI();
// Functions // Functions
void play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo); void play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo);

View File

@ -12,7 +12,7 @@
// Name: hibit() // Name: hibit()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int mystring::hibit(unsigned int n) int MyString::hibit(unsigned int n)
{ {
n |= (n >> 1); n |= (n >> 1);
n |= (n >> 2); n |= (n >> 2);
@ -23,36 +23,36 @@ int mystring::hibit(unsigned int n)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: mystring() // Name: MyString()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
mystring::mystring() MyString::MyString()
{ {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: mystring() // Name: MyString()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
mystring::mystring(const char *cStr) MyString::MyString(const char *cStr)
{ {
assign(cStr); assign(cStr);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: mystring() // Name: MyString()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
mystring::mystring(const WCHAR *cStr) MyString::MyString(const WCHAR *cStr)
{ {
assign(cStr); assign(cStr);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: mystring() // Name: MyString()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
mystring::~mystring() MyString::~MyString()
{ {
if (strA != nullptr) { if (strA != nullptr) {
delete[] strA; strA = nullptr; delete[] strA; strA = nullptr;
@ -70,7 +70,7 @@ mystring::~mystring()
// Name: c_strA() // Name: c_strA()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const char *mystring::c_strA() const char *MyString::c_strA()
{ {
return strA; return strA;
} }
@ -79,7 +79,7 @@ const char *mystring::c_strA()
// Name: c_strW() // Name: c_strW()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const WCHAR *mystring::c_strW() const WCHAR *MyString::c_strW()
{ {
return strW; return strW;
} }
@ -88,14 +88,14 @@ const WCHAR *mystring::c_strW()
// Name: assign() // Name: assign()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
mystring &mystring::assign(const char *cStr) MyString &MyString::assign(const char *cStr)
{ {
// locals // locals
size_t convertedChars = 0; size_t convertedChars = 0;
size_t newLength = strlen(cStr); size_t newLength = strlen(cStr);
size_t newReserved = (size_t)hibit((unsigned int)newLength) * 2; size_t newReserved = (size_t)hibit((unsigned int)newLength) * 2;
if (reserved < newReserved) this->~mystring(); if (reserved < newReserved) this->~MyString();
if (strA == nullptr) strA = new char[newReserved]; if (strA == nullptr) strA = new char[newReserved];
if (strW == nullptr) strW = new WCHAR[newReserved]; if (strW == nullptr) strW = new WCHAR[newReserved];
@ -112,14 +112,14 @@ mystring &mystring::assign(const char *cStr)
// Name: assign() // Name: assign()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
mystring &mystring::assign(const WCHAR *cStr) MyString &MyString::assign(const WCHAR *cStr)
{ {
// locals // locals
size_t returnValue; size_t returnValue;
size_t newLength = wcslen(cStr); size_t newLength = wcslen(cStr);
size_t newReserved = (size_t)hibit((unsigned int)newLength) * 2; size_t newReserved = (size_t)hibit((unsigned int)newLength) * 2;
if (reserved < newReserved) this->~mystring(); if (reserved < newReserved) this->~MyString();
if (strA == nullptr) strA = new char[newReserved]; if (strA == nullptr) strA = new char[newReserved];
if (strW == nullptr) strW = new WCHAR[newReserved]; if (strW == nullptr) strW = new WCHAR[newReserved];

View File

@ -21,7 +21,7 @@ using namespace std;
// general functions // general functions
bool readAsciiData(HANDLE hFile, double *pData, unsigned int numValues, unsigned char decimalSeperator, unsigned char columnSeparator); bool readAsciiData(HANDLE hFile, double *pData, unsigned int numValues, unsigned char decimalSeperator, unsigned char columnSeparator);
class mystring class MyString
{ {
private: private:
@ -36,15 +36,15 @@ private:
public: public:
// functions // functions
mystring(); MyString();
mystring(const char *cStr); MyString(const char *cStr);
mystring(const WCHAR *cStr); MyString(const WCHAR *cStr);
~mystring(); ~MyString();
const char *c_strA(); const char *c_strA();
const WCHAR *c_strW(); const WCHAR *c_strW();
mystring &assign(const char *cStr); MyString &assign(const char *cStr);
mystring &assign(const WCHAR *cStr); MyString &assign(const WCHAR *cStr);
static int hibit(unsigned int n); static int hibit(unsigned int n);
}; };

View File

@ -9,10 +9,10 @@
#include "threadManager.h" #include "threadManager.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: threadManagerClass() // Name: ThreadManager()
// Desc: threadManagerClass class constructor // Desc: ThreadManager class constructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
threadManagerClass::threadManagerClass() ThreadManager::ThreadManager()
{ {
// locals // locals
unsigned int curThreadNo; unsigned int curThreadNo;
@ -40,10 +40,10 @@ threadManagerClass::threadManagerClass()
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: ~threadManagerClass() // Name: ~ThreadManager()
// Desc: threadManagerClass class destructor // Desc: ThreadManager class destructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
threadManagerClass::~threadManagerClass() ThreadManager::~ThreadManager()
{ {
// locals // locals
unsigned int curThreadNo; unsigned int curThreadNo;
@ -64,7 +64,7 @@ threadManagerClass::~threadManagerClass()
// Name: waitForOtherThreads() // Name: waitForOtherThreads()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void threadManagerClass::waitForOtherThreads(unsigned int threadNo) void ThreadManager::waitForOtherThreads(unsigned int threadNo)
{ {
// wait if other threads are still waiting at the barrier // wait if other threads are still waiting at the barrier
//cout << endl << "thread=" << threadNo << ", numThreadsPassedBarrier= " << numThreadsPassedBarrier << ": " << "while (numThreadsPassedBarrier>0)"; //cout << endl << "thread=" << threadNo << ", numThreadsPassedBarrier= " << numThreadsPassedBarrier << ": " << "while (numThreadsPassedBarrier>0)";
@ -108,7 +108,7 @@ void threadManagerClass::waitForOtherThreads(unsigned int threadNo)
// Name: getNumThreads() // Name: getNumThreads()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int threadManagerClass::getNumThreads() unsigned int ThreadManager::getNumThreads()
{ {
return numThreads; return numThreads;
} }
@ -117,7 +117,7 @@ unsigned int threadManagerClass::getNumThreads()
// Name: setNumThreads() // Name: setNumThreads()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool threadManagerClass::setNumThreads(unsigned int newNumThreads) bool ThreadManager::setNumThreads(unsigned int newNumThreads)
{ {
// cancel if any thread running // cancel if any thread running
EnterCriticalSection(&csBarrier); EnterCriticalSection(&csBarrier);
@ -139,7 +139,7 @@ bool threadManagerClass::setNumThreads(unsigned int newNumThreads)
// Name: pauseExecution() // Name: pauseExecution()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void threadManagerClass::pauseExecution() void ThreadManager::pauseExecution()
{ {
for (unsigned int curThread = 0; curThread < numThreads; curThread++) { for (unsigned int curThread = 0; curThread < numThreads; curThread++) {
@ -159,7 +159,7 @@ void threadManagerClass::pauseExecution()
// Desc: Stops executeParallelLoop() before the next iteration. // Desc: Stops executeParallelLoop() before the next iteration.
// When executeInParallel() was called, user has to handle cancellation by himself. // When executeInParallel() was called, user has to handle cancellation by himself.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void threadManagerClass::cancelExecution() void ThreadManager::cancelExecution()
{ {
termineAllThreads = true; termineAllThreads = true;
executionCancelled = true; executionCancelled = true;
@ -172,7 +172,7 @@ void threadManagerClass::cancelExecution()
// Name: uncancelExecution() // Name: uncancelExecution()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void threadManagerClass::uncancelExecution() void ThreadManager::uncancelExecution()
{ {
executionCancelled = false; executionCancelled = false;
} }
@ -181,7 +181,7 @@ void threadManagerClass::uncancelExecution()
// Name: wasExecutionCancelled() // Name: wasExecutionCancelled()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool threadManagerClass::wasExecutionCancelled() bool ThreadManager::wasExecutionCancelled()
{ {
return executionCancelled; return executionCancelled;
} }
@ -190,7 +190,7 @@ bool threadManagerClass::wasExecutionCancelled()
// Name: getThreadId() // Name: getThreadId()
// Desc: Returns a number from 0 to 'numThreads'-1. Returns 0 if the function fails. // Desc: Returns a number from 0 to 'numThreads'-1. Returns 0 if the function fails.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int threadManagerClass::getThreadNumber() unsigned int ThreadManager::getThreadNumber()
{ {
// locals // locals
DWORD curThreadId = GetCurrentThreadId(); DWORD curThreadId = GetCurrentThreadId();
@ -208,7 +208,7 @@ unsigned int threadManagerClass::getThreadNumber()
// Name: executeInParallel() // Name: executeInParallel()
// Desc: lpParameter is an array of size numThreads. // Desc: lpParameter is an array of size numThreads.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int threadManagerClass::executeInParallel(DWORD threadProc(void *pParameter), void *pParameter, unsigned int parameterStructSize) unsigned int ThreadManager::executeInParallel(DWORD threadProc(void *pParameter), void *pParameter, unsigned int parameterStructSize)
{ {
// locals // locals
unsigned int curThreadNo; unsigned int curThreadNo;
@ -264,7 +264,7 @@ unsigned int threadManagerClass::executeInParallel(DWORD threadProc(void *pPara
// lpParameter - an array of size numThreads // lpParameter - an array of size numThreads
// finalValue - this value is part of the iteration, meaning that index ranges from initialValue to finalValue including both border values // finalValue - this value is part of the iteration, meaning that index ranges from initialValue to finalValue including both border values
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int threadManagerClass::executeParallelLoop(DWORD threadProc(void *pParameter, int index), unsigned int ThreadManager::executeParallelLoop(DWORD threadProc(void *pParameter, int index),
void *pParameter, void *pParameter,
unsigned int parameterStructSize, unsigned int parameterStructSize,
unsigned int scheduleType, unsigned int scheduleType,
@ -284,7 +284,7 @@ unsigned int threadManagerClass::executeParallelLoop(DWORD threadProc(void *p
int numIterations = (finalValue - initialValue) / inkrement + 1; // total number of iterations int numIterations = (finalValue - initialValue) / inkrement + 1; // total number of iterations
int chunkSize = 0; // number of iterations per chunk int chunkSize = 0; // number of iterations per chunk
SIZE_T dwStackSize = 0; // initital stack size of each thread. 0 means default size ~1MB SIZE_T dwStackSize = 0; // initital stack size of each thread. 0 means default size ~1MB
forLoopStruct *forLoopParameters = new forLoopStruct[numThreads]; // ForLoop *forLoopParameters = new ForLoop[numThreads]; //
// globals // globals
termineAllThreads = false; termineAllThreads = false;
@ -361,10 +361,10 @@ unsigned int threadManagerClass::executeParallelLoop(DWORD threadProc(void *p
// Name: threadForLoop() // Name: threadForLoop()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
DWORD WINAPI threadManagerClass::threadForLoop(LPVOID lpParameter) DWORD WINAPI ThreadManager::threadForLoop(LPVOID lpParameter)
{ {
// locals // locals
forLoopStruct *forLoopParameters = (forLoopStruct *)lpParameter; ForLoop *forLoopParameters = (ForLoop *)lpParameter;
int index; int index;
switch (forLoopParameters->scheduleType) { switch (forLoopParameters->scheduleType) {

View File

@ -36,12 +36,12 @@ using namespace std; // use standard library namespace
/*** Klassen *********************************************************/ /*** Klassen *********************************************************/
class threadManagerClass class ThreadManager
{ {
private: private:
// structures // structures
struct forLoopStruct struct ForLoop
{ {
unsigned int scheduleType; unsigned int scheduleType;
int inkrement; int inkrement;
@ -49,7 +49,7 @@ private:
int finalValue; int finalValue;
void *pParameter; void *pParameter;
DWORD(*threadProc)(void *pParameter, int index); // pointer to the user function to be executed by the threads DWORD(*threadProc)(void *pParameter, int index); // pointer to the user function to be executed by the threads
threadManagerClass *threadManager; ThreadManager *threadManager;
}; };
// Variables // Variables
@ -71,7 +71,7 @@ private:
public: public:
class threadVarsArrayItem class ThreadVarsArrayItem
{ {
public: public:
unsigned int curThreadNo; unsigned int curThreadNo;
@ -87,13 +87,13 @@ public:
}; };
}; };
template <class varType> class threadVarsArray template <class varType> class ThreadVarsArray
{ {
public: public:
unsigned int numberOfThreads; unsigned int numberOfThreads;
varType *item; varType *item;
threadVarsArray(unsigned int numberOfThreads, varType &master) ThreadVarsArray(unsigned int numberOfThreads, varType &master)
{ {
this->numberOfThreads = numberOfThreads; this->numberOfThreads = numberOfThreads;
this->item = new varType[numberOfThreads]; this->item = new varType[numberOfThreads];
@ -105,7 +105,7 @@ public:
} }
}; };
~threadVarsArray() ~ThreadVarsArray()
{ {
for (unsigned int threadCounter = 0; threadCounter < numberOfThreads; threadCounter++) { for (unsigned int threadCounter = 0; threadCounter < numberOfThreads; threadCounter++) {
item[threadCounter].destroyElement(); item[threadCounter].destroyElement();
@ -132,8 +132,8 @@ public:
}; };
// Constructor / destructor // Constructor / destructor
threadManagerClass(); ThreadManager();
~threadManagerClass(); ~ThreadManager();
// Functions // Functions
unsigned int getThreadNumber(); unsigned int getThreadNumber();