This commit is contained in:
Daniel Marjamäki 2016-08-07 14:30:09 +02:00
parent 70ccfa5947
commit fab2c96622
2 changed files with 27 additions and 15 deletions

View File

@ -352,10 +352,11 @@ unsigned int ThreadExecutor::check()
HANDLE *threadHandles = new HANDLE[_settings.jobs]; HANDLE *threadHandles = new HANDLE[_settings.jobs];
_itNextFile = _files.begin(); _itNextFile = _files.begin();
_itNextFileSettings = _settings.fileSettings.begin();
_processedFiles = 0; _processedFiles = 0;
_processedSize = 0; _processedSize = 0;
_totalFiles = _files.size(); _totalFiles = _files.size() + _settings.fileSettings.size();
_totalFileSize = 0; _totalFileSize = 0;
for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
_totalFileSize += i->second; _totalFileSize += i->second;
@ -415,7 +416,8 @@ unsigned int __stdcall ThreadExecutor::threadProc(void *args)
unsigned int result = 0; unsigned int result = 0;
ThreadExecutor *threadExecutor = static_cast<ThreadExecutor*>(args); ThreadExecutor *threadExecutor = static_cast<ThreadExecutor*>(args);
std::map<std::string, std::size_t>::const_iterator &it = threadExecutor->_itNextFile; std::map<std::string, std::size_t>::const_iterator &itFile = threadExecutor->_itNextFile;
std::list<Settings::FileSettings>::const_iterator &itFileSettings = threadExecutor->_itNextFileSettings;
// guard static members of CppCheck against concurrent access // guard static members of CppCheck against concurrent access
EnterCriticalSection(&threadExecutor->_fileSync); EnterCriticalSection(&threadExecutor->_fileSync);
@ -424,24 +426,32 @@ unsigned int __stdcall ThreadExecutor::threadProc(void *args)
fileChecker.settings() = threadExecutor->_settings; fileChecker.settings() = threadExecutor->_settings;
for (;;) { for (;;) {
if (it == threadExecutor->_files.end()) { if (itFile == threadExecutor->_files.end() && itFileSettings == threadExecutor->_settings.fileSettings.end()) {
LeaveCriticalSection(&threadExecutor->_fileSync); LeaveCriticalSection(&threadExecutor->_fileSync);
break; break;
} }
const std::string &file = it->first;
const std::size_t fileSize = it->second;
++it;
LeaveCriticalSection(&threadExecutor->_fileSync); std::size_t fileSize = 0;
if (itFile != threadExecutor->_files.end()) {
const std::string &file = itFile->first;
fileSize = itFile->second;
++itFile;
std::map<std::string, std::string>::const_iterator fileContent = threadExecutor->_fileContents.find(file); LeaveCriticalSection(&threadExecutor->_fileSync);
if (fileContent != threadExecutor->_fileContents.end()) {
// File content was given as a string std::map<std::string, std::string>::const_iterator fileContent = threadExecutor->_fileContents.find(file);
result += fileChecker.check(file, fileContent->second); if (fileContent != threadExecutor->_fileContents.end()) {
} else { // File content was given as a string
// Read file from a file result += fileChecker.check(file, fileContent->second);
result += fileChecker.check(file); } else {
// Read file from a file
result += fileChecker.check(file);
}
} else { // file settings..
const Settings::FileSettings &fs = *itFileSettings;
++itFileSettings;
LeaveCriticalSection(&threadExecutor->_fileSync);
result += fileChecker.check(fs);
} }
EnterCriticalSection(&threadExecutor->_fileSync); EnterCriticalSection(&threadExecutor->_fileSync);

View File

@ -23,6 +23,7 @@
#include <string> #include <string>
#include <list> #include <list>
#include "errorlogger.h" #include "errorlogger.h"
#include "settings.h" // Settings::FileSettings
#if (defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__) #if (defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__)
#define THREADING_MODEL_FORK #define THREADING_MODEL_FORK
@ -109,6 +110,7 @@ private:
std::map<std::string, std::string> _fileContents; std::map<std::string, std::string> _fileContents;
std::map<std::string, std::size_t>::const_iterator _itNextFile; std::map<std::string, std::size_t>::const_iterator _itNextFile;
std::list<Settings::FileSettings>::const_iterator _itNextFileSettings;
std::size_t _processedFiles; std::size_t _processedFiles;
std::size_t _totalFiles; std::size_t _totalFiles;
std::size_t _processedSize; std::size_t _processedSize;