Small improvement in InitializationThread class.

This commit is contained in:
LoRd_MuldeR 2013-10-16 03:31:14 +02:00
parent d0e994b347
commit e7872a52ae
2 changed files with 27 additions and 11 deletions

View File

@ -172,7 +172,11 @@ void FileAnalyzer::run()
//Create thread pool //Create thread pool
if(!m_pool) m_pool = new QThreadPool(); if(!m_pool) m_pool = new QThreadPool();
m_pool->setMaxThreadCount(qBound(2, ((QThread::idealThreadCount() * 3) / 2), 12)); const int idealThreadCount = QThread::idealThreadCount();
if(idealThreadCount > 0)
{
m_pool->setMaxThreadCount(qBound(2, ((idealThreadCount * 3) / 2), 12));
}
//Start first N threads //Start first N threads
QTimer::singleShot(0, this, SLOT(initializeTasks())); QTimer::singleShot(0, this, SLOT(initializeTasks()));

View File

@ -57,13 +57,21 @@ public:
static void clearFlags(void) static void clearFlags(void)
{ {
s_mutex.lock();
s_bAbort = s_bCustom = false; s_bAbort = s_bCustom = false;
s_errMsg[0] = '\0'; s_errMsg[0] = '\0';
s_mutex.unlock();
} }
static bool getAbort(void) { return s_bAbort; } static bool getAbort(void) { bool ret; s_mutex.lock(); ret = s_bAbort; s_mutex.unlock(); return ret; }
static bool getCustom(void) { return s_bCustom; } static bool getCustom(void) { bool ret; s_mutex.lock(); ret = s_bCustom; s_mutex.unlock(); return ret; }
static char *const getError(void) { return s_errMsg; }
static void getError(char *buffer, const size_t buffSize)
{
s_mutex.lock();
strncpy_s(buffer, 1024, s_errMsg, _TRUNCATE);
s_mutex.unlock();
}
protected: protected:
void run(void) void run(void)
@ -89,7 +97,7 @@ protected:
if(lockedFile) if(lockedFile)
{ {
QMutexLocker lock(&s_mutex); //QMutexLocker lock(&s_mutex);
lamexp_register_tool(m_toolShortName, lockedFile, version, &m_toolTag); lamexp_register_tool(m_toolShortName, lockedFile, version, &m_toolTag);
} }
} }
@ -99,7 +107,11 @@ protected:
qWarning("At least one of the required tools could not be initialized:\n%s", errorMsg); qWarning("At least one of the required tools could not be initialized:\n%s", errorMsg);
if(s_mutex.tryLock()) if(s_mutex.tryLock())
{ {
if(!s_bAbort) { s_bAbort = true; strncpy_s(s_errMsg, 1024, errorMsg, _TRUNCATE); } if(!s_bAbort)
{
strncpy_s(s_errMsg, 1024, errorMsg, _TRUNCATE);
s_bAbort = true;
}
s_mutex.unlock(); s_mutex.unlock();
} }
} }
@ -110,8 +122,8 @@ private:
const QString m_toolName; const QString m_toolName;
const QString m_toolShortName; const QString m_toolShortName;
const QString m_toolTag; const QString m_toolTag;
const QByteArray m_toolHash;
const unsigned int m_toolVersion; const unsigned int m_toolVersion;
const QByteArray m_toolHash;
static volatile bool s_bAbort; static volatile bool s_bAbort;
static volatile bool s_bCustom; static volatile bool s_bCustom;
@ -163,8 +175,6 @@ void InitializationThread::run()
//Hack to disable x64 on Wine, as x64 binaries won't run under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64) //Hack to disable x64 on Wine, as x64 binaries won't run under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64)
if(cpuSupport & CPU_TYPE_X64_ALL) if(cpuSupport & CPU_TYPE_X64_ALL)
{ {
//DWORD osVerNo = lamexp_get_os_version();
//if((HIWORD(osVerNo) == 6) && (LOWORD(osVerNo) == 2))
if(lamexp_detect_wine()) if(lamexp_detect_wine())
{ {
qWarning("Running under Wine on a 64-Bit system. Going to disable all x64 support!\n"); qWarning("Running under Wine on a 64-Bit system. Going to disable all x64 support!\n");
@ -214,7 +224,7 @@ void InitializationThread::run()
QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath(); QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
QThreadPool *pool = new QThreadPool(); QThreadPool *pool = new QThreadPool();
int idealThreadCount = QThread::idealThreadCount(); const int idealThreadCount = QThread::idealThreadCount();
if(idealThreadCount > 0) if(idealThreadCount > 0)
{ {
pool->setMaxThreadCount(idealThreadCount * 2); pool->setMaxThreadCount(idealThreadCount * 2);
@ -265,7 +275,9 @@ void InitializationThread::run()
//Make sure all files were extracted correctly //Make sure all files were extracted correctly
if(ExtractorTask::getAbort()) if(ExtractorTask::getAbort())
{ {
qFatal("At least one of the required tools could not be initialized:\n%s", ExtractorTask::getError()); char errorMsg[1024];
ExtractorTask::getError(errorMsg, 1024);
qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg);
return; return;
} }