CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/FileLoaders/RamCachingFileLoader.h
Views: 1401
// Copyright (c) 2015- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <vector>20#include <mutex>21#include <thread>2223#include "Common/CommonTypes.h"24#include "Core/Loaders.h"2526class RamCachingFileLoader : public ProxiedFileLoader {27public:28RamCachingFileLoader(FileLoader *backend);29~RamCachingFileLoader();3031bool Exists() override;32bool ExistsFast() override;33bool IsDirectory() override;34s64 FileSize() override;3536size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) override {37return ReadAt(absolutePos, bytes * count, data, flags) / bytes;38}39size_t ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags = Flags::NONE) override;4041void Cancel() override;4243private:44void InitCache();45void ShutdownCache();46size_t ReadFromCache(s64 pos, size_t bytes, void *data);47// Guaranteed to read at least one block into the cache.48void SaveIntoCache(s64 pos, size_t bytes, Flags flags);49void StartReadAhead(s64 pos);50u32 NextAheadBlock();5152enum {53BLOCK_SIZE = 65536,54BLOCK_SHIFT = 16,55MAX_BLOCKS_PER_READ = 16,56BLOCK_READAHEAD = 4,57};5859s64 filesize_ = 0;60u8 *cache_ = nullptr;61int exists_ = -1;62int isDirectory_ = -1;6364std::vector<u8> blocks_;65std::mutex blocksMutex_;66u32 aheadRemaining_;67s64 aheadPos_;68std::thread aheadThread_;69bool aheadThreadRunning_ = false;70bool aheadCancel_ = false;71};727374