From c5af4ed4e5a5efb25c97f70563d8da9c6dcfc42d Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Sat, 11 Jun 2016 02:25:19 +0200 Subject: [PATCH] data: Fixed files being consumed by multiple threads --- src/lib/utility/file/FileRegister.cpp | 50 +++++++++++++-------------- src/lib/utility/file/FileRegister.h | 3 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/lib/utility/file/FileRegister.cpp b/src/lib/utility/file/FileRegister.cpp index e7a03c48..0af1ef2a 100644 --- a/src/lib/utility/file/FileRegister.cpp +++ b/src/lib/utility/file/FileRegister.cpp @@ -99,46 +99,44 @@ bool FileRegister::fileIsParsed(const FilePath& filePath) const bool FileRegister::sourceFileIsParsed(const FilePath& filePath) const { + std::lock_guard lock(m_sourceFileMutex); + + std::map::const_iterator it = m_sourceFilePaths.find(filePath); + if (it == m_sourceFilePaths.end()) { - std::lock_guard lock(m_sourceFileMutex); - - std::map::const_iterator it = m_sourceFilePaths.find(filePath); - if (it == m_sourceFilePaths.end()) - { - return false; - } - - if (it->second == STATE_PARSED) - { - return true; - } - return false; } + + if (it->second == STATE_PARSED) + { + return true; + } + + return false; } bool FileRegister::includeFileIsParsed(const FilePath& filePath) const { + std::lock_guard lock(m_includeFileMutex); + + std::map::const_iterator it = m_includeFilePaths.find(filePath); + if (it == m_includeFilePaths.end()) { - std::lock_guard lock(m_includeFileMutex); - - std::map::const_iterator it = m_includeFilePaths.find(filePath); - if (it == m_includeFilePaths.end()) - { - return false; - } - - if (it->second == STATE_PARSED) - { - return true; - } - return false; } + + if (it->second == STATE_PARSED) + { + return true; + } + + return false; } FilePath FileRegister::consumeSourceFile() { + std::lock_guard lock(m_consumeFileMutex); + std::vector paths = getUnparsedSourceFilePaths(); FilePath path; diff --git a/src/lib/utility/file/FileRegister.h b/src/lib/utility/file/FileRegister.h index 401204c5..6f7e0535 100644 --- a/src/lib/utility/file/FileRegister.h +++ b/src/lib/utility/file/FileRegister.h @@ -65,7 +65,8 @@ private: mutable std::mutex m_sourceFileMutex; mutable std::mutex m_includeFileMutex; mutable std::mutex m_threadFileMutex; - mutable std::mutex m_fileManagerMutex; + + std::mutex m_consumeFileMutex; }; #endif // FILE_REGISTER_H