summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys/vfs_real.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/file_sys/vfs_real.h')
-rw-r--r--src/core/file_sys/vfs_real.h29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h
index b92c84316..f29c69fbd 100644
--- a/src/core/file_sys/vfs_real.h
+++ b/src/core/file_sys/vfs_real.h
@@ -4,7 +4,7 @@
#pragma once
#include <string_view>
-#include <boost/container/flat_map.hpp>
+#include "common/intrusive_list.h"
#include "core/file_sys/mode.h"
#include "core/file_sys/vfs.h"
@@ -14,6 +14,12 @@ class IOFile;
namespace FileSys {
+struct FileReference : public Common::IntrusiveListBaseNode<FileReference> {
+ FileReference(std::shared_ptr<Common::FS::IOFile>&& f) : file(f) {}
+ std::shared_ptr<Common::FS::IOFile> file;
+};
+
+class RealVfsFile;
class RealVfsFilesystem : public VfsFilesystem {
public:
RealVfsFilesystem();
@@ -35,7 +41,20 @@ public:
bool DeleteDirectory(std::string_view path) override;
private:
- boost::container::flat_map<std::string, std::weak_ptr<Common::FS::IOFile>> cache;
+ using ReferenceListType = Common::IntrusiveListBaseTraits<FileReference>::ListType;
+ ReferenceListType open_references;
+ ReferenceListType closed_references;
+ size_t num_open_files{};
+
+private:
+ friend class RealVfsFile;
+ void RefreshReference(const std::string& path, Mode perms, FileReference& reference);
+ void DropReference(std::unique_ptr<FileReference>&& reference);
+ void EvictSingleReference();
+
+private:
+ void InsertReferenceIntoList(FileReference& reference);
+ void RemoveReferenceFromList(FileReference& reference);
};
// An implementation of VfsFile that represents a file on the user's computer.
@@ -57,13 +76,11 @@ public:
bool Rename(std::string_view name) override;
private:
- RealVfsFile(RealVfsFilesystem& base, std::shared_ptr<Common::FS::IOFile> backing,
+ RealVfsFile(RealVfsFilesystem& base, std::unique_ptr<FileReference> reference,
const std::string& path, Mode perms = Mode::Read);
- void Close();
-
RealVfsFilesystem& base;
- std::shared_ptr<Common::FS::IOFile> backing;
+ std::unique_ptr<FileReference> reference;
std::string path;
std::string parent_path;
std::vector<std::string> path_components;