Move file system mutex to irrlicht
This commit is contained in:
parent
efe1070be7
commit
8df6bdf7c8
@ -94,12 +94,14 @@ IReadFile* CFileSystem::createAndOpenFile(const io::path& filename)
|
||||
IReadFile* file = 0;
|
||||
u32 i;
|
||||
|
||||
std::unique_lock<std::recursive_mutex> ul(m_file_archives_mutex);
|
||||
for (i=0; i< FileArchives.size(); ++i)
|
||||
{
|
||||
file = FileArchives[i]->createAndOpenFile(filename);
|
||||
if (file)
|
||||
return file;
|
||||
}
|
||||
ul.unlock();
|
||||
|
||||
// Create the file using an absolute path so that it matches
|
||||
// the scheme used by CNullDriver::getTexture().
|
||||
@ -178,6 +180,7 @@ bool CFileSystem::moveFileArchive(u32 sourceIndex, s32 relative)
|
||||
bool r = false;
|
||||
const s32 dest = (s32) sourceIndex + relative;
|
||||
const s32 dir = relative < 0 ? -1 : 1;
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
const s32 sourceEnd = ((s32) FileArchives.size() ) - 1;
|
||||
IFileArchive *t;
|
||||
|
||||
@ -287,7 +290,9 @@ bool CFileSystem::addFileArchive(const io::path& filename, bool ignoreCase,
|
||||
|
||||
if (archive)
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> ul(m_file_archives_mutex);
|
||||
FileArchives.push_back(archive);
|
||||
ul.unlock();
|
||||
if (password.size())
|
||||
archive->Password=password;
|
||||
if (retArchive)
|
||||
@ -308,6 +313,7 @@ bool CFileSystem::changeArchivePassword(const path& filename,
|
||||
const core::stringc& password,
|
||||
IFileArchive** archive)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
for (s32 idx = 0; idx < (s32)FileArchives.size(); ++idx)
|
||||
{
|
||||
// TODO: This should go into a path normalization method
|
||||
@ -393,7 +399,9 @@ bool CFileSystem::addFileArchive(IReadFile* file, bool ignoreCase,
|
||||
|
||||
if (archive)
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> ul(m_file_archives_mutex);
|
||||
FileArchives.push_back(archive);
|
||||
ul.unlock();
|
||||
if (password.size())
|
||||
archive->Password=password;
|
||||
if (retArchive)
|
||||
@ -413,6 +421,7 @@ bool CFileSystem::addFileArchive(IReadFile* file, bool ignoreCase,
|
||||
//! Adds an archive to the file system.
|
||||
bool CFileSystem::addFileArchive(IFileArchive* archive)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
for (u32 i=0; i < FileArchives.size(); ++i)
|
||||
{
|
||||
if (archive == FileArchives[i])
|
||||
@ -428,15 +437,17 @@ bool CFileSystem::addFileArchive(IFileArchive* archive)
|
||||
|
||||
void CFileSystem::removeAllFileArchives()
|
||||
{
|
||||
for (u32 index = 0; index < FileArchives.size(); index++)
|
||||
FileArchives[index]->drop();
|
||||
FileArchives.clear();
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
for (u32 index = 0; index < FileArchives.size(); index++)
|
||||
FileArchives[index]->drop();
|
||||
FileArchives.clear();
|
||||
}
|
||||
|
||||
|
||||
//! removes an archive from the file system.
|
||||
bool CFileSystem::removeFileArchive(u32 index)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
bool ret = false;
|
||||
if (index < FileArchives.size())
|
||||
{
|
||||
@ -453,6 +464,7 @@ bool CFileSystem::removeFileArchive(u32 index)
|
||||
bool CFileSystem::removeFileArchive(const io::path& filename)
|
||||
{
|
||||
const path absPath = getAbsolutePath(filename);
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
for (u32 i=0; i < FileArchives.size(); ++i)
|
||||
{
|
||||
if (absPath == FileArchives[i]->getFileList()->getPath())
|
||||
@ -466,6 +478,7 @@ bool CFileSystem::removeFileArchive(const io::path& filename)
|
||||
//! Removes an archive from the file system.
|
||||
bool CFileSystem::removeFileArchive(const IFileArchive* archive)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
for (u32 i=0; i < FileArchives.size(); ++i)
|
||||
{
|
||||
if (archive == FileArchives[i])
|
||||
@ -482,12 +495,14 @@ bool CFileSystem::removeFileArchive(const IFileArchive* archive)
|
||||
//! gets an archive
|
||||
u32 CFileSystem::getFileArchiveCount() const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
return FileArchives.size();
|
||||
}
|
||||
|
||||
|
||||
IFileArchive* CFileSystem::getFileArchive(u32 index)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
return index < getFileArchiveCount() ? FileArchives[index] : 0;
|
||||
}
|
||||
|
||||
@ -917,6 +932,7 @@ IFileList* CFileSystem::createFileList(const io::path& directory)
|
||||
r->addItem(Path + _IRR_TEXT(".."), 0, 0, true, 0);
|
||||
|
||||
//! merge archives
|
||||
std::lock_guard<std::recursive_mutex> lock(m_file_archives_mutex);
|
||||
for (u32 i=0; i < FileArchives.size(); ++i)
|
||||
{
|
||||
const IFileList *merge = FileArchives[i]->getFileList();
|
||||
@ -985,9 +1001,11 @@ bool CFileSystem::existFileThreadSafe(const path& filename) const
|
||||
//! determines if a file exists and would be able to be opened.
|
||||
bool CFileSystem::existFile(const io::path& filename) const
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> ul(m_file_archives_mutex);
|
||||
for (u32 i=0; i < FileArchives.size(); ++i)
|
||||
if (FileArchives[i]->getFileList()->findFile(filename)!=-1)
|
||||
return true;
|
||||
ul.unlock();
|
||||
return existFileThreadSafe(filename);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "IFileSystem.h"
|
||||
#include "irrArray.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace io
|
||||
@ -172,6 +174,8 @@ private:
|
||||
core::array<IArchiveLoader*> ArchiveLoader;
|
||||
//! currently attached Archives
|
||||
core::array<IFileArchive*> FileArchives;
|
||||
|
||||
mutable std::recursive_mutex m_file_archives_mutex;
|
||||
};
|
||||
|
||||
|
||||
|
@ -530,7 +530,6 @@ 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;
|
||||
@ -633,8 +632,6 @@ 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),
|
||||
@ -662,8 +659,6 @@ 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),
|
||||
@ -693,7 +688,6 @@ void FileManager::popTextureSearchPath()
|
||||
{
|
||||
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));
|
||||
@ -707,7 +701,6 @@ void FileManager::popModelSearchPath()
|
||||
{
|
||||
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));
|
||||
|
@ -25,7 +25,6 @@
|
||||
* Contains generic utility classes for file I/O (especially XML handling).
|
||||
*/
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
@ -66,8 +65,6 @@ 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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user