mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-06 09:06:55 +00:00
Fix two mutex issues in CachingFileLoader. See #9370
This commit is contained in:
parent
fb0b82f6e8
commit
4a2812a30d
@ -132,7 +132,7 @@ void CachingFileLoader::ShutdownCache() {
|
||||
sleep_ms(1);
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
std::lock_guard<std::recursive_mutex> guard(blocksMutex_);
|
||||
for (auto block : blocks_) {
|
||||
delete [] block.second.ptr;
|
||||
}
|
||||
@ -148,7 +148,7 @@ size_t CachingFileLoader::ReadFromCache(s64 pos, size_t bytes, void *data) {
|
||||
size_t offset = (size_t)(pos - (cacheStartPos << BLOCK_SHIFT));
|
||||
u8 *p = (u8 *)data;
|
||||
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
std::lock_guard<std::recursive_mutex> guard(blocksMutex_);
|
||||
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
|
||||
auto block = blocks_.find(i);
|
||||
if (block == blocks_.end()) {
|
||||
@ -170,7 +170,7 @@ void CachingFileLoader::SaveIntoCache(s64 pos, size_t bytes, Flags flags, bool r
|
||||
s64 cacheStartPos = pos >> BLOCK_SHIFT;
|
||||
s64 cacheEndPos = (pos + bytes - 1) >> BLOCK_SHIFT;
|
||||
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
std::lock_guard<std::recursive_mutex> guard(blocksMutex_);
|
||||
size_t blocksToRead = 0;
|
||||
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
|
||||
auto block = blocks_.find(i);
|
||||
@ -235,7 +235,7 @@ bool CachingFileLoader::MakeCacheSpaceFor(size_t blocks, bool readingAhead) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
std::lock_guard<std::recursive_mutex> guard(blocksMutex_);
|
||||
while (cacheSize_ > goal) {
|
||||
u64 minGeneration = generation_;
|
||||
|
||||
@ -274,7 +274,7 @@ bool CachingFileLoader::MakeCacheSpaceFor(size_t blocks, bool readingAhead) {
|
||||
}
|
||||
|
||||
void CachingFileLoader::StartReadAhead(s64 pos) {
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
std::lock_guard<std::recursive_mutex> guard(blocksMutex_);
|
||||
if (aheadThread_) {
|
||||
// Already going.
|
||||
return;
|
||||
@ -288,14 +288,14 @@ void CachingFileLoader::StartReadAhead(s64 pos) {
|
||||
std::thread th([this, pos] {
|
||||
setCurrentThreadName("FileLoaderReadAhead");
|
||||
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
std::unique_lock<std::recursive_mutex> guard(blocksMutex_);
|
||||
s64 cacheStartPos = pos >> BLOCK_SHIFT;
|
||||
s64 cacheEndPos = cacheStartPos + BLOCK_READAHEAD - 1;
|
||||
|
||||
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
|
||||
auto block = blocks_.find(i);
|
||||
if (block == blocks_.end()) {
|
||||
blocksMutex_.unlock();
|
||||
guard.unlock();
|
||||
SaveIntoCache(i << BLOCK_SHIFT, BLOCK_SIZE * BLOCK_READAHEAD, Flags::NONE, true);
|
||||
break;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ private:
|
||||
};
|
||||
|
||||
std::map<s64, BlockInfo> blocks_;
|
||||
std::mutex blocksMutex_;
|
||||
std::recursive_mutex blocksMutex_;
|
||||
mutable std::mutex backendMutex_;
|
||||
bool aheadThread_;
|
||||
bool prepared_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user