size_t CachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) { Prepare(); if (absolutePos >= filesize_) { bytes = 0; } else if (absolutePos + (s64)bytes >= filesize_) { bytes = (size_t)(filesize_ - absolutePos); } size_t readSize = 0; if ((flags & Flags::HINT_UNCACHED) != 0) { readSize = backend_->ReadAt(absolutePos, bytes, data, flags); } else { readSize = ReadFromCache(absolutePos, bytes, data); // While in case the cache size is too small for the entire read. while (readSize < bytes) { SaveIntoCache(absolutePos + readSize, bytes - readSize, flags); size_t bytesFromCache = ReadFromCache(absolutePos + readSize, bytes - readSize, (u8 *)data + readSize); readSize += bytesFromCache; if (bytesFromCache == 0) { // We can't read any more. break; } } StartReadAhead(absolutePos + readSize); } return readSize; }
size_t CachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data) { size_t readSize = ReadFromCache(absolutePos, bytes, data); // While in case the cache size is too small for the entire read. while (readSize < bytes) { SaveIntoCache(absolutePos + readSize, bytes - readSize); readSize += ReadFromCache(absolutePos + readSize, bytes - readSize, (u8 *)data + readSize); } StartReadAhead(absolutePos + readSize); filepos_ = absolutePos + readSize; return readSize; }
size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data) { size_t readSize = 0; if (cache_ == nullptr) { lock_guard guard(backendMutex_); readSize = backend_->ReadAt(absolutePos, bytes, data); } else { readSize = ReadFromCache(absolutePos, bytes, data); // While in case the cache size is too small for the entire read. while (readSize < bytes) { SaveIntoCache(absolutePos + readSize, bytes - readSize); readSize += ReadFromCache(absolutePos + readSize, bytes - readSize, (u8 *)data + readSize); } } StartReadAhead(absolutePos + readSize); filepos_ = absolutePos + readSize; return readSize; }
size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) { size_t readSize = 0; if (cache_ == nullptr || (flags & Flags::HINT_UNCACHED) != 0) { lock_guard guard(backendMutex_); readSize = backend_->ReadAt(absolutePos, bytes, data, flags); } else { readSize = ReadFromCache(absolutePos, bytes, data); // While in case the cache size is too small for the entire read. while (readSize < bytes) { SaveIntoCache(absolutePos + readSize, bytes - readSize, flags); size_t bytesFromCache = ReadFromCache(absolutePos + readSize, bytes - readSize, (u8 *)data + readSize); readSize += bytesFromCache; if (bytesFromCache == 0) { // We can't read any more. break; } } StartReadAhead(absolutePos + readSize); } filepos_ = absolutePos + readSize; return readSize; }