Some minor tweaks to the multi-threaded FileAnalyzer class.

This commit is contained in:
LoRd_MuldeR 2012-05-04 16:40:02 +02:00
parent b00b527897
commit 7d36e9d82e
3 changed files with 13 additions and 5 deletions

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 5
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 998
#define VER_LAMEXP_BUILD 1001
///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!)

View File

@ -124,6 +124,11 @@ void FileAnalyzer::run()
AnalyzeTask::reset();
QThreadPool *pool = new QThreadPool();
if(pool->maxThreadCount() < 2)
{
pool->setMaxThreadCount(2);
}
while(!(m_inputFiles.isEmpty() || m_bAborted))
{
@ -142,7 +147,7 @@ void FileAnalyzer::run()
while(!pool->tryStart(task))
{
QThread::msleep(125); //No more free threads, wait for active threads!
pool->waitForDone(250); //No more free threads, wait for active threads!
if(m_abortFlag) { LAMEXP_DELETE(task); break; }
}
@ -164,14 +169,13 @@ void FileAnalyzer::run()
pool->waitForDone();
LAMEXP_DELETE(pool);
if(m_bAborted)
{
qWarning("Operation cancelled by user!");
return;
}
qDebug("All files added.\n");
m_bSuccess = true;
}

View File

@ -692,6 +692,9 @@ unsigned __int64 AnalyzeTask::makeThreadIdx(void)
void AnalyzeTask::waitForPreviousThreads(void)
{
//This function will block until all threads with a *lower* index have terminated.
//Required to make sure that the files will be added in the "correct" order!
for(int i = 0; i < 240; i++)
{
QReadLocker lock(&s_lock);
@ -699,8 +702,9 @@ void AnalyzeTask::waitForPreviousThreads(void)
{
break;
}
DWORD sleepInterval = 100 + (static_cast<DWORD>(qBound(1ui64, m_threadIdx - s_threadIdx_finished, 8ui64)) * 25);
lock.unlock();
Sleep(125);
Sleep(sleepInterval);
}
}