fix: some more thread-safety improvements

This commit is contained in:
maybegreat48
2025-05-30 20:18:59 -04:00
parent 4d154d7f61
commit 2a24ae3041
4 changed files with 16 additions and 3 deletions
+6
View File
@@ -6,6 +6,7 @@ namespace YimMenu
{
std::optional<int> PatternCache::GetCachedOffsetImpl(PatternHash hash)
{
std::lock_guard lock(m_Mutex);
if (auto it = m_Data.find(hash.GetHash()); it != m_Data.end())
return it->second;
@@ -14,11 +15,14 @@ namespace YimMenu
void PatternCache::UpdateCachedOffsetImpl(PatternHash hash, int offset)
{
std::lock_guard lock(m_Mutex);
m_Data[hash.GetHash()] = offset;
}
void PatternCache::InitImpl()
{
std::lock_guard lock(m_Mutex);
auto file = FileMgr::GetProjectFile("./pattern_cache.bin");
if (file.Exists())
{
@@ -40,6 +44,8 @@ namespace YimMenu
void PatternCache::UpdateImpl()
{
std::lock_guard lock(m_Mutex);
auto file = FileMgr::GetProjectFile("./pattern_cache.bin");
std::ofstream stream(file.Path(), std::ios_base::binary);
+1
View File
@@ -7,6 +7,7 @@ namespace YimMenu
{
bool m_Initialized;
std::unordered_map<std::uint64_t, int> m_Data;
std::mutex m_Mutex;
public:
PatternCache() :
+6
View File
@@ -11,6 +11,9 @@ namespace YimMenu
{
if (m_Applied || !g_Running)
return;
std::lock_guard lock(m_Mutex); // this function should be thread-safe, but doesn't hurt
unsigned long old_protect;
unsigned long temp;
VirtualProtect(m_Address, m_Size, PAGE_EXECUTE_READWRITE, &old_protect);
@@ -23,6 +26,9 @@ namespace YimMenu
{
if (!m_Applied)
return;
std::lock_guard lock(m_Mutex);
unsigned long old_protect;
unsigned long temp;
VirtualProtect(m_Address, m_Size, PAGE_EXECUTE_READWRITE, &old_protect);
+3 -3
View File
@@ -5,9 +5,9 @@
namespace YimMenu::Features
{
static IntCommand _NetworkTimeHour{"networktimehour", "Hour", "Set hour (0–23)", 0, 23, 12};
static IntCommand _NetworkTimeMinute{"networktimeminute", "Minute", "Set minute (0–59)", 0, 59, 0};
static IntCommand _NetworkTimeSecond{"networktimesecond", "Second", "Set second (0–59)", 0, 59, 0};
static IntCommand _NetworkTimeHour{"networktimehour", "Hour", "Set hour (0-23)", 0, 23, 12};
static IntCommand _NetworkTimeMinute{"networktimeminute", "Minute", "Set minute (0-59)", 0, 59, 0};
static IntCommand _NetworkTimeSecond{"networktimesecond", "Second", "Set second (0-59)", 0, 59, 0};
class SetNetworkTime : public Command