Some code refactoring regarding the QWaitCondition/QMutex in FileAnalyzer_Task.
This commit is contained in:
parent
814b725fe3
commit
9175daae0d
@ -30,7 +30,7 @@
|
||||
#define VER_LAMEXP_MINOR_LO 5
|
||||
#define VER_LAMEXP_TYPE Alpha
|
||||
#define VER_LAMEXP_PATCH 1
|
||||
#define VER_LAMEXP_BUILD 1018
|
||||
#define VER_LAMEXP_BUILD 1019
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Tool versions (minimum expected versions!)
|
||||
|
@ -133,7 +133,11 @@ void FileAnalyzer::run()
|
||||
QThreadPool *pool = new QThreadPool();
|
||||
QThread::msleep(333);
|
||||
|
||||
if(pool->maxThreadCount() < 2)
|
||||
if(QThread::idealThreadCount() > 1)
|
||||
{
|
||||
pool->setMaxThreadCount((QThread::idealThreadCount() * 3) / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
pool->setMaxThreadCount(2);
|
||||
}
|
||||
@ -177,7 +181,7 @@ void FileAnalyzer::run()
|
||||
{
|
||||
emit progressMaxChanged(nFiles += count);
|
||||
}
|
||||
QThread::msleep(5);
|
||||
QThread::msleep(8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,10 @@ AnalyzeTask::AnalyzeTask(const QString &inputFile, const QString &templateFile,
|
||||
|
||||
AnalyzeTask::~AnalyzeTask(void)
|
||||
{
|
||||
QWriteLocker lock(&s_lock);
|
||||
s_waitMutex.lock();
|
||||
s_threadIdx_finished = qMax(s_threadIdx_finished, m_threadIdx + 1ui64);
|
||||
s_waitMutex.unlock();
|
||||
|
||||
s_waitCond.wakeAll();
|
||||
}
|
||||
|
||||
@ -99,8 +101,10 @@ void AnalyzeTask::run()
|
||||
qWarning("WARNING: Caught an in exception AnalyzeTask thread!");
|
||||
}
|
||||
|
||||
QWriteLocker lock(&s_lock);
|
||||
s_waitMutex.lock();
|
||||
s_threadIdx_finished = qMax(s_threadIdx_finished, m_threadIdx + 1ui64);
|
||||
s_waitMutex.unlock();
|
||||
|
||||
s_waitCond.wakeAll();
|
||||
}
|
||||
|
||||
@ -710,28 +714,34 @@ unsigned int AnalyzeTask::parseDuration(const QString &str)
|
||||
|
||||
unsigned __int64 AnalyzeTask::makeThreadIdx(void)
|
||||
{
|
||||
QWriteLocker lock(&s_lock);
|
||||
return s_threadIdx_created++;
|
||||
s_waitMutex.lock();
|
||||
unsigned __int64 idx = s_threadIdx_created++;
|
||||
s_waitMutex.unlock();
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
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 < 64; i++)
|
||||
{
|
||||
QReadLocker lock(&s_lock);
|
||||
s_waitMutex.lock();
|
||||
|
||||
if((s_threadIdx_finished >= m_threadIdx) || *m_abortFlag)
|
||||
{
|
||||
s_waitMutex.unlock();
|
||||
break;
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
if(!AnalyzeTask::waitForOneThread(1250))
|
||||
if(!s_waitCond.wait(&s_waitMutex, 1250))
|
||||
{
|
||||
qWarning("FileAnalyzerTask: Timeout, retrying!");
|
||||
}
|
||||
|
||||
s_waitMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -787,12 +797,20 @@ int AnalyzeTask::getAdditionalFiles(QStringList &fileList)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AnalyzeTask::waitForOneThread(unsigned long timeout)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
s_waitMutex.lock();
|
||||
ret = s_waitCond.wait(&s_waitMutex, timeout);
|
||||
s_waitMutex.unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AnalyzeTask::reset(void)
|
||||
{
|
||||
QWriteLocker lock(&s_lock);
|
||||
|
||||
s_threadIdx_created = 0;
|
||||
s_threadIdx_finished = 0;
|
||||
s_filesAccepted = 0;
|
||||
s_filesRejected = 0;
|
||||
s_filesDenied = 0;
|
||||
@ -800,8 +818,13 @@ void AnalyzeTask::reset(void)
|
||||
s_filesCueSheet = 0;
|
||||
s_additionalFiles.clear();
|
||||
s_recentlyAdded.clear();
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
s_waitMutex.lock();
|
||||
s_threadIdx_created = 0;
|
||||
s_threadIdx_finished = 0;
|
||||
s_waitMutex.unlock();
|
||||
}
|
||||
////////////////////////////////////////////////////////////
|
||||
// EVENTS
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -54,14 +54,7 @@ public:
|
||||
static unsigned int filesCueSheet(void);
|
||||
|
||||
//Wait till the next running thread terminates
|
||||
static __forceinline bool waitForOneThread(unsigned long timeout)
|
||||
{
|
||||
bool ret = false;
|
||||
s_waitMutex.lock();
|
||||
ret = s_waitCond.wait(&s_waitMutex, timeout);
|
||||
s_waitMutex.unlock();
|
||||
return ret;
|
||||
}
|
||||
static bool waitForOneThread(unsigned long timeout);
|
||||
|
||||
signals:
|
||||
void fileSelected(const QString &fileName);
|
||||
@ -107,21 +100,19 @@ private:
|
||||
|
||||
volatile bool *m_abortFlag;
|
||||
|
||||
static QReadWriteLock s_lock;
|
||||
static QMutex s_waitMutex;
|
||||
static QWaitCondition s_waitCond;
|
||||
|
||||
static unsigned __int64 s_threadIdx_created;
|
||||
static unsigned __int64 s_threadIdx_finished;
|
||||
|
||||
static QStringList s_recentlyAdded;
|
||||
static QStringList s_additionalFiles;
|
||||
|
||||
static QReadWriteLock s_lock;
|
||||
static unsigned int s_filesAccepted;
|
||||
static unsigned int s_filesRejected;
|
||||
static unsigned int s_filesDenied;
|
||||
static unsigned int s_filesDummyCDDA;
|
||||
static unsigned int s_filesCueSheet;
|
||||
static QStringList s_recentlyAdded;
|
||||
static QStringList s_additionalFiles;
|
||||
|
||||
static unsigned __int64 makeThreadIdx(void);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user