summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-02-05 19:49:06 +0100
committerAdmiral H. Curtiss <pikachu025@gmail.com>2022-02-05 21:50:34 +0100
commit56ea1c1d74f349a1ed412b7e604decf0fadc9f6c (patch)
treea8da612b0cbab15f5d68246f179586f30d49dc2f /Source/Core
parent09a0ba06c02b87dd799febc133c2cd24d94f44cb (diff)
Core/State: Guard SaveAs() and LoadAs() with a mutex.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/State.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp
index f89c1fc79e..e3f382a610 100644
--- a/Source/Core/Core/State.cpp
+++ b/Source/Core/Core/State.cpp
@@ -64,7 +64,7 @@ static AfterLoadCallbackFunc s_on_after_load_callback;
// Temporary undo state buffer
static std::vector<u8> g_undo_load_buffer;
static std::vector<u8> g_current_buffer;
-static bool s_load_or_save_in_progress;
+static std::mutex s_load_or_save_in_progress_mutex;
static std::mutex g_cs_undo_load_buffer;
static std::mutex g_cs_current_buffer;
@@ -403,11 +403,10 @@ static void CompressAndDumpState(CompressAndDumpState_args save_args)
void SaveAs(const std::string& filename, bool wait)
{
- if (s_load_or_save_in_progress)
+ std::unique_lock lk(s_load_or_save_in_progress_mutex, std::try_to_lock);
+ if (!lk)
return;
- s_load_or_save_in_progress = true;
-
Core::RunOnCPUThread(
[&] {
// Measure the size of the buffer.
@@ -446,8 +445,6 @@ void SaveAs(const std::string& filename, bool wait)
}
},
true);
-
- s_load_or_save_in_progress = false;
}
bool ReadHeader(const std::string& filename, StateHeader& header)
@@ -550,17 +547,18 @@ static void LoadFileStateData(const std::string& filename, std::vector<u8>& ret_
void LoadAs(const std::string& filename)
{
- if (!Core::IsRunning() || s_load_or_save_in_progress)
- {
+ if (!Core::IsRunning())
return;
- }
- else if (NetPlay::IsNetPlayRunning())
+
+ if (NetPlay::IsNetPlayRunning())
{
OSD::AddMessage("Loading savestates is disabled in Netplay to prevent desyncs");
return;
}
- s_load_or_save_in_progress = true;
+ std::unique_lock lk(s_load_or_save_in_progress_mutex, std::try_to_lock);
+ if (!lk)
+ return;
Core::RunOnCPUThread(
[&] {
@@ -617,8 +615,6 @@ void LoadAs(const std::string& filename)
s_on_after_load_callback();
},
true);
-
- s_load_or_save_in_progress = false;
}
void SetOnAfterLoadCallback(AfterLoadCallbackFunc callback)