- use read/write locking via shared_mutex
- lock in IsEmuHandle
This commit is contained in:
parent
7c51e2e34b
commit
f818e43fc7
|
@ -256,14 +256,14 @@ EmuHandle::EmuHandle(EmuNtObject* ntObject)
|
|||
}
|
||||
|
||||
std::unordered_map<HANDLE, EmuHandle*> 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<std::mutex> 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<std::mutex> 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());
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
// ******************************************************************
|
||||
// * 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<HANDLE, EmuHandle*> EmuHandleLookup;
|
||||
static std::mutex EmuHandleLookupLock;
|
||||
static std::shared_mutex EmuHandleLookupLock;
|
||||
};
|
||||
|
||||
// ******************************************************************
|
||||
|
|
Loading…
Reference in New Issue