mirror of
https://github.com/YimMenu/YimMenuV2.git
synced 2026-10-10 03:43:15 +08:00
fix: some more thread-safety improvements
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace YimMenu
|
||||
{
|
||||
bool m_Initialized;
|
||||
std::unordered_map<std::uint64_t, int> m_Data;
|
||||
std::mutex m_Mutex;
|
||||
|
||||
public:
|
||||
PatternCache() :
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user