From 7d36e9d82e5302ebdf79483e49b53857740506a5 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Fri, 4 May 2012 16:40:02 +0200 Subject: [PATCH] Some minor tweaks to the multi-threaded FileAnalyzer class. --- src/Config.h | 2 +- src/Thread_FileAnalyzer.cpp | 10 +++++++--- src/Thread_FileAnalyzer_Task.cpp | 6 +++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Config.h b/src/Config.h index c13a2052..2c3066b4 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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!) diff --git a/src/Thread_FileAnalyzer.cpp b/src/Thread_FileAnalyzer.cpp index 5e5b9e37..4abfdf44 100644 --- a/src/Thread_FileAnalyzer.cpp +++ b/src/Thread_FileAnalyzer.cpp @@ -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; } diff --git a/src/Thread_FileAnalyzer_Task.cpp b/src/Thread_FileAnalyzer_Task.cpp index dce1a237..ca841f0b 100644 --- a/src/Thread_FileAnalyzer_Task.cpp +++ b/src/Thread_FileAnalyzer_Task.cpp @@ -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(qBound(1ui64, m_threadIdx - s_threadIdx_finished, 8ui64)) * 25); lock.unlock(); - Sleep(125); + Sleep(sleepInterval); } } -- 2.11.4.GIT