void ThreadHandler::Check(const Settings &settings, bool all) { if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0 || settings.jobs == 0) { qDebug() << "Can't start checking if there's no files to check or if check is in progress."; emit Done(); return; } SetThreadCount(settings.jobs); mRunningThreadCount = mThreads.size(); if (mResults.GetFileCount() < mRunningThreadCount) { mRunningThreadCount = mResults.GetFileCount(); } for (int i = 0; i < mRunningThreadCount; i++) { mThreads[i]->Check(settings); } // Date and time when checking starts.. mCheckStartTime = QDateTime::currentDateTime(); mAnalyseWholeProgram = true; mTime.start(); }
void ThreadHandler::Check(const Settings &settings, bool recheck) { if (recheck && mRunningThreadCount == 0) { // only recheck changed files mResults.SetFiles(GetReCheckFiles()); } if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0 || settings._jobs <= 0) { qDebug() << "Can't start checking if there's no files to check or if check is in progress."; emit Done(); return; } SetThreadCount(settings._jobs); mRunningThreadCount = mThreads.size(); if (mResults.GetFileCount() < mRunningThreadCount) { mRunningThreadCount = mResults.GetFileCount(); } for (int i = 0; i < mRunningThreadCount; i++) { mThreads[i]->Check(settings); } // Date and time when checking starts.. mCheckStartTime = QDateTime::currentDateTime(); mTime.start(); }
ThreadHandler::ThreadHandler(QObject *parent) : QObject(parent), mScanDuration(0), mRunningThreadCount(0) { SetThreadCount(1); }
ThreadHandler::ThreadHandler(QObject *parent) : QObject(parent), mScanDuration(0), mRunningThreadCount(0), mAnalyseWholeProgram(false) { SetThreadCount(1); }
void SetThreadCount(int num) { int curThreads = GetNumThreads(); if (curThreads < num) { #ifndef UNITSYNC if (hasOGLthreads) { try { for (int i = curThreads; i<num; ++i) { thread_group.push_back(new COffscreenGLThread(boost::bind(&WorkerLoop, i))); } } catch (const opengl_error& gle) { // shared gl context creation failed :< SetThreadCount(0); hasOGLthreads = false; curThreads = GetNumThreads(); } } #endif if (!hasOGLthreads) { for (int i = curThreads; i<num; ++i) { thread_group.push_back(new boost::thread(boost::bind(&WorkerLoop, i))); } } } else { for (int i = curThreads; i>num && i>1; --i) { assert(!thread_group.empty()); auto taskgroup = std::make_shared<ParallelTaskGroup<const std::function<void()>>>(); taskgroup->enqueue_unique(GetNumThreads() - 1, []{ exitThread = true; }); ThreadPool::PushTaskGroup(taskgroup); #ifndef UNITSYNC if (hasOGLthreads) { auto th = reinterpret_cast<COffscreenGLThread*>(thread_group.back()); th->join(); delete th; } else #endif { auto th = reinterpret_cast<boost::thread*>(thread_group.back()); th->join(); delete th; } thread_group.pop_back(); } if (num == 0) assert(thread_group.empty()); } }
CJobScheduler::CThreadPool::~CThreadPool() { SetThreadCount(0); }