New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SaveState: Fix for race condition in SaveAs(...) #3095
SaveState: Fix for race condition in SaveAs(...) #3095
Conversation
@@ -280,8 +281,17 @@ struct CompressAndDumpState_args | |||
static void CompressAndDumpState(CompressAndDumpState_args save_args) | |||
{ | |||
std::lock_guard<std::mutex> lk(*save_args.buffer_mutex); | |||
if (!save_args.wait) | |||
|
|||
auto onExit= wxMakeGuard([]() |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
af3388e
to
c252645
Compare
@dolphin-emu-bot rebuild |
template<class Callable> | ||
ScopeGuard(Callable && finalizer) : m_finalizer(std::forward<Callable>(finalizer)) {} | ||
|
||
ScopeGuard(ScopeGuard && other) : m_finalizer(std::move(other.m_finalizer)) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
ScopeGuard.h also needs to be added to the vcxproj file in Common. |
30b3f78
to
173df73
Compare
@@ -280,8 +281,13 @@ struct CompressAndDumpState_args | |||
static void CompressAndDumpState(CompressAndDumpState_args save_args) | |||
{ | |||
std::lock_guard<std::mutex> lk(*save_args.buffer_mutex); | |||
if (!save_args.wait) | |||
|
|||
Common::ScopeGuard on_exit([]() |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
173df73
to
bc53464
Compare
|
||
//By creating ScopeGuard instance we ensure that g_compressAndDumpStateSyncEvent.Set() | ||
//will be called then we leave this function, even if it's because of exception being thrown. | ||
//Both ScopeGuard' and IOFile's finalization occur at respective object destruction time. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
7916b99
to
aceba9e
Compare
…file to flush/close). g_compressAndDumpStateSyncEvent was Set() before destruction of file object (i.e. before flushing changes and closing file). Also, adds Common::ScopeGuard wrapper for RAII.
aceba9e
to
cd19d53
Compare
LGTM. |
SaveState: Fix for race condition in SaveAs(...)
"wait" didn't actually waited for file to flush/close. That sometimes produced savestates with partial data or wrong (zeroed) gameId.
g_compressAndDumpStateSyncEvent.Set() was called before destruction of file object (i.e. before flushing changes and closing file). I've used RAII to correct that.