Change the scope of the mutex when hooking into the FSReadfile to avoid a possible deadlook when exiting some games.

This commit is contained in:
Maschell 2022-09-10 14:18:39 +02:00
parent 6d868eabb9
commit b10a288150

View File

@ -451,6 +451,7 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t *outTitleCount,
uint32_t titleCount = *outTitleCount; uint32_t titleCount = *outTitleCount;
{
std::lock_guard<std::mutex> lock(fileInfosMutex); std::lock_guard<std::mutex> lock(fileInfosMutex);
readCustomTitlesFromSD(); readCustomTitlesFromSD();
@ -458,6 +459,7 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t *outTitleCount,
memcpy(&(titleList[titleCount]), &(gFileInfo->titleInfo), sizeof(MCPTitleListType)); memcpy(&(titleList[titleCount]), &(gFileInfo->titleInfo), sizeof(MCPTitleListType));
titleCount++; titleCount++;
} }
}
*outTitleCount = titleCount; *outTitleCount = titleCount;
@ -540,12 +542,14 @@ DECL_FUNCTION(FSStatus, FSCloseFile, FSClient *client, FSCmdBlock *block, FSFile
} }
DECL_FUNCTION(FSStatus, FSReadFile, FSClient *client, FSCmdBlock *block, uint8_t *buffer, uint32_t size, uint32_t count, FSFileHandle handle, uint32_t unk1, uint32_t flags) { DECL_FUNCTION(FSStatus, FSReadFile, FSClient *client, FSCmdBlock *block, uint8_t *buffer, uint32_t size, uint32_t count, FSFileHandle handle, uint32_t unk1, uint32_t flags) {
{
const std::lock_guard<std::mutex> lock(fileReaderListMutex); const std::lock_guard<std::mutex> lock(fileReaderListMutex);
for (auto &reader : openFileReaders) { for (auto &reader : openFileReaders) {
if ((uint32_t) reader.get() == (uint32_t) handle) { if ((uint32_t) reader.get() == (uint32_t) handle) {
return (FSStatus) (reader->read(buffer, size * count) / size); return (FSStatus) (reader->read(buffer, size * count) / size);
} }
} }
}
FSStatus result = real_FSReadFile(client, block, buffer, size, count, handle, unk1, flags); FSStatus result = real_FSReadFile(client, block, buffer, size, count, handle, unk1, flags);
return result; return result;
} }