mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-15 15:30:29 +02:00
The core and the headless tools no longer use mutexes, condition variables, spinlocks, std::atomic, std::thread or volatile flags. Threads hand off through libretro-common's retro_atomic and rthreads plus a few small pieces on top of them in Common/Thread: Thread, MpscQueue, EventCounter, ParkingLot waits and ReaderGate. Every wait blocks until it's woken; nothing polls on a timer. State that only one thread touches just loses its lock. The PSP filesystem, sceIo and the savedata dialog now belong to the emulation thread: async reads and writes run when they're queued and complete later in emulated time, and the IO and savedata threads are gone. The friend finder only talks to the adhoc server and hands what it gets to the emulation thread. GPU init always runs on the thread that starts the game. The Vulkan render and compile queues, pipeline and render pass caches, delete list and SPIR-V cache, the GL render queue, the software renderer's jit caches, the file loader caches, the web debugger, UPnP, input, savestates, logging and the GE debugger all hand off through queues and atomics. The IR jit's spinning profiler thread goes. A CPU thread with nothing to run now sleeps until work is queued instead of spinning. Headless with --debugger waits for a client while stopped, and ends the run once every client that connected has left. Web server shutdown keeps servicing the CPU queue until the server has finished.
84 lines
2.5 KiB
C++
84 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <set>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
#include "Common/CommonWindows.h"
|
|
|
|
#include "ext/lzma-sdk/7z.h"
|
|
#include "ext/lzma-sdk/7zFile.h"
|
|
|
|
#include "Common/File/VFS/VFS.h"
|
|
#include "Common/File/FileUtil.h"
|
|
#include "Common/File/Path.h"
|
|
|
|
// Not thread safe: extraction shares one stream and block cache, so use it from one thread at a time.
|
|
class SevenZipFileReader : public VFSBackend {
|
|
public:
|
|
static SevenZipFileReader *Create(const Path &archivePath, std::string_view inArchivePath, bool logErrors = true);
|
|
~SevenZipFileReader();
|
|
|
|
bool IsValid() const { return valid_; }
|
|
|
|
// Use delete[] on the returned value.
|
|
uint8_t *ReadFile(std::string_view path, size_t *size) override;
|
|
|
|
VFSFileReference *GetFile(std::string_view path) override;
|
|
bool GetFileInfo(VFSFileReference *vfsReference, File::FileInfo *fileInfo) override;
|
|
void ReleaseFile(VFSFileReference *vfsReference) override;
|
|
|
|
VFSOpenFile *OpenFileForRead(VFSFileReference *vfsReference, size_t *size) override;
|
|
void Rewind(VFSOpenFile *vfsOpenFile) override;
|
|
size_t Read(VFSOpenFile *vfsOpenFile, void *buffer, size_t length) override;
|
|
void CloseFile(VFSOpenFile *vfsOpenFile) override;
|
|
|
|
bool GetFileListing(std::string_view path, std::vector<File::FileInfo> *listing, const char *filter) override;
|
|
bool GetFileInfo(std::string_view path, File::FileInfo *info) override;
|
|
std::string toString() const override {
|
|
std::string retval = archivePath_.ToVisualString();
|
|
if (!inArchivePath_.empty()) {
|
|
retval += ": ";
|
|
retval += inArchivePath_;
|
|
}
|
|
return retval;
|
|
}
|
|
|
|
private:
|
|
struct SevenZipEntry {
|
|
std::string path;
|
|
bool isDirectory = false;
|
|
uint64_t size = 0;
|
|
};
|
|
|
|
SevenZipFileReader(const Path &archivePath, const std::string &inArchivePath);
|
|
bool OpenArchive(bool logErrors);
|
|
void CloseArchive();
|
|
bool BuildEntryCache();
|
|
bool FindEntry(std::string_view path, UInt32 *index, bool *isDirectory = nullptr) const;
|
|
std::string ResolvePath(std::string_view path) const;
|
|
std::string ReadEntryPath(UInt32 index) const;
|
|
uint8_t *ExtractFile(UInt32 fileIndex, size_t *size);
|
|
|
|
static void *Alloc(ISzAllocPtr p, size_t size);
|
|
static void Free(ISzAllocPtr p, void *address);
|
|
|
|
Path archivePath_;
|
|
std::string inArchivePath_;
|
|
|
|
CFileInStream archiveStream_;
|
|
CLookToRead2 lookStream_;
|
|
ISzAlloc allocImp_;
|
|
ISzAlloc allocTempImp_;
|
|
CSzArEx db_;
|
|
Byte *lookStreamBuf_ = nullptr;
|
|
Byte *cachedBlock_ = nullptr;
|
|
size_t cachedBlockSize_ = 0;
|
|
UInt32 blockIndex_ = 0xFFFFFFFF;
|
|
bool valid_ = false;
|
|
|
|
std::vector<SevenZipEntry> entries_;
|
|
};
|