mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Loaders: Add cancelation to all file loaders.
Mainly, for HTTP which might be stalled trying to connect (especially if you're not near your PC right now and it's in your recent, for example.)
This commit is contained in:
1 parent
6e3cb0cd48
commit
ee5b68f1fc
11 files changed
+87
-43
No files matched your search
@@ -28,7 +28,7 @@
|
||||
|
||||
// Takes ownership of backend.
|
||||
RamCachingFileLoader::RamCachingFileLoader(FileLoader *backend)
|
||||
: filesize_(0), backend_(backend), exists_(-1), isDirectory_(-1), aheadThread_(false) {
|
||||
: backend_(backend) {
|
||||
filesize_ = backend->FileSize();
|
||||
if (filesize_ > 0) {
|
||||
InitCache();
|
||||
@@ -107,11 +107,7 @@ void RamCachingFileLoader::InitCache() {
|
||||
}
|
||||
|
||||
void RamCachingFileLoader::ShutdownCache() {
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
// Try to have the thread stop.
|
||||
aheadRemaining_ = 0;
|
||||
}
|
||||
Cancel();
|
||||
|
||||
// We can't delete while the thread is running, so have to wait.
|
||||
// This should only happen from the menu.
|
||||
@@ -127,6 +123,15 @@ void RamCachingFileLoader::ShutdownCache() {
|
||||
}
|
||||
}
|
||||
|
||||
void RamCachingFileLoader::Cancel() {
|
||||
if (aheadThread_) {
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
aheadCancel_ = true;
|
||||
}
|
||||
|
||||
backend_->Cancel();
|
||||
}
|
||||
|
||||
size_t RamCachingFileLoader::ReadFromCache(s64 pos, size_t bytes, void *data) {
|
||||
s64 cacheStartPos = pos >> BLOCK_SHIFT;
|
||||
s64 cacheEndPos = (pos + bytes - 1) >> BLOCK_SHIFT;
|
||||
@@ -220,10 +225,11 @@ void RamCachingFileLoader::StartReadAhead(s64 pos) {
|
||||
}
|
||||
|
||||
aheadThread_ = true;
|
||||
aheadCancel_ = false;
|
||||
std::thread th([this] {
|
||||
setCurrentThreadName("FileLoaderReadAhead");
|
||||
|
||||
while (aheadRemaining_ != 0) {
|
||||
while (aheadRemaining_ != 0 && !aheadCancel_) {
|
||||
// Where should we look?
|
||||
const u32 cacheStartPos = NextAheadBlock();
|
||||
if (cacheStartPos == 0xFFFFFFFF) {
|
||||
|
||||
Reference in new issue
Block a user