1
// Copyright (c) 2015- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
21
#include "base/mutex.h"
22
#include "Common/CommonTypes.h"
23
#include "Core/Loaders.h"
25
class RamCachingFileLoader : public FileLoader {
27
RamCachingFileLoader(FileLoader *backend);
28
~RamCachingFileLoader() override;
30
bool Exists() override;
31
bool ExistsFast() override;
32
bool IsDirectory() override;
33
s64 FileSize() override;
34
std::string Path() const override;
36
void Seek(s64 absolutePos) override;
37
size_t Read(size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) override {
38
return ReadAt(filepos_, bytes, count, data, flags);
40
size_t Read(size_t bytes, void *data, Flags flags = Flags::NONE) override {
41
return ReadAt(filepos_, bytes, data, flags);
43
size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) override {
44
return ReadAt(absolutePos, bytes * count, data, flags) / bytes;
46
size_t ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags = Flags::NONE) override;
51
size_t ReadFromCache(s64 pos, size_t bytes, void *data);
52
// Guaranteed to read at least one block into the cache.
53
void SaveIntoCache(s64 pos, size_t bytes, Flags flags);
54
void StartReadAhead(s64 pos);
60
MAX_BLOCKS_PER_READ = 16,
71
std::vector<u8> blocks_;
72
recursive_mutex blocksMutex_;
73
mutable recursive_mutex backendMutex_;