diff --git a/src/core/kernel/support/EmuFile.cpp b/src/core/kernel/support/EmuFile.cpp index 0931a9961..0748f6c8b 100644 --- a/src/core/kernel/support/EmuFile.cpp +++ b/src/core/kernel/support/EmuFile.cpp @@ -256,14 +256,14 @@ EmuHandle::EmuHandle(EmuNtObject* ntObject) } std::unordered_map EmuHandle::EmuHandleLookup = {}; -std::mutex EmuHandle::EmuHandleLookupLock = {}; +std::shared_mutex EmuHandle::EmuHandleLookupLock = {}; EmuHandle* EmuHandle::CreateEmuHandle(EmuNtObject* ntObject) { auto emuHandle = new EmuHandle(ntObject); // Register EmuHandle { - const std::lock_guard scopedLock(EmuHandleLookupLock); + std::unique_lock scopedLock(EmuHandleLookupLock); EmuHandleLookup.emplace(EmuHandleToHandle(emuHandle), emuHandle); } @@ -276,7 +276,7 @@ NTSTATUS EmuHandle::NtClose() // Unregister the handle if (status == STATUS_SUCCESS) { - const std::lock_guard scopedLock(EmuHandleLookupLock); + std::unique_lock scopedLock(EmuHandleLookupLock); EmuHandleLookup.erase(EmuHandleToHandle(this)); } @@ -285,6 +285,7 @@ NTSTATUS EmuHandle::NtClose() bool EmuHandle::IsEmuHandle(HANDLE Handle) { + std::shared_lock scopedLock(EmuHandleLookupLock); auto iter = EmuHandleLookup.find(Handle); return !(iter == EmuHandleLookup.end()); } diff --git a/src/core/kernel/support/EmuFile.h b/src/core/kernel/support/EmuFile.h index c8be90781..9780fea0b 100644 --- a/src/core/kernel/support/EmuFile.h +++ b/src/core/kernel/support/EmuFile.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include // ****************************************************************** // * prevent name collisions @@ -176,7 +176,7 @@ private: // But titles may attempt to operate on invalid handles with the high bit set // Test case: Amped sets a handle value to 0xFDFDFDFD (coincidentally a VS debugger guard value) static std::unordered_map EmuHandleLookup; - static std::mutex EmuHandleLookupLock; + static std::shared_mutex EmuHandleLookupLock; }; // ******************************************************************