Add lock for calling fileExists from other thread in addons manager

This commit is contained in:
Benau 2018-10-27 15:55:17 +08:00
parent 6ce42d19b1
commit a77b897cd5
2 changed files with 11 additions and 2 deletions

View File

@ -415,6 +415,7 @@ FileManager::~FileManager()
*/
bool FileManager::fileExists(const std::string& path) const
{
std::lock_guard<std::mutex> lock(m_file_system_lock);
#ifdef DEBUG
bool exists = m_file_system->existFile(path.c_str());
if(exists) return true;
@ -517,6 +518,8 @@ io::path FileManager::createAbsoluteFilename(const std::string &f)
*/
void FileManager::pushModelSearchPath(const std::string& path)
{
std::lock_guard<std::mutex> lock(m_file_system_lock);
m_model_search_path.push_back(path);
const int n=m_file_system->getFileArchiveCount();
m_file_system->addFileArchive(createAbsoluteFilename(path),
@ -544,6 +547,8 @@ void FileManager::pushModelSearchPath(const std::string& path)
*/
void FileManager::pushTextureSearchPath(const std::string& path, const std::string& container_id)
{
std::lock_guard<std::mutex> lock(m_file_system_lock);
m_texture_search_path.push_back(TextureSearchPath(path, container_id));
const int n=m_file_system->getFileArchiveCount();
m_file_system->addFileArchive(createAbsoluteFilename(path),
@ -571,8 +576,9 @@ void FileManager::pushTextureSearchPath(const std::string& path, const std::stri
*/
void FileManager::popTextureSearchPath()
{
if(!m_texture_search_path.empty())
if (!m_texture_search_path.empty())
{
std::lock_guard<std::mutex> lock(m_file_system_lock);
TextureSearchPath dir = m_texture_search_path.back();
m_texture_search_path.pop_back();
m_file_system->removeFileArchive(createAbsoluteFilename(dir.m_texture_search_path));
@ -584,8 +590,9 @@ void FileManager::popTextureSearchPath()
*/
void FileManager::popModelSearchPath()
{
if(!m_model_search_path.empty())
if (!m_model_search_path.empty())
{
std::lock_guard<std::mutex> lock(m_file_system_lock);
std::string dir = m_model_search_path.back();
m_model_search_path.pop_back();
m_file_system->removeFileArchive(createAbsoluteFilename(dir));

View File

@ -25,6 +25,7 @@
* Contains generic utility classes for file I/O (especially XML handling).
*/
#include <mutex>
#include <string>
#include <vector>
#include <set>
@ -66,6 +67,7 @@ public:
ASSET_COUNT};
private:
mutable std::mutex m_file_system_lock;
/** The names of the various subdirectories of the asset types. */
std::vector< std::string > m_subdir_name;