Skip to content
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

Merged

Conversation

void-ghost
Copy link
Contributor

"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.

@@ -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.

@Helios747
Copy link
Contributor

@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.

@lioncash
Copy link
Member

ScopeGuard.h also needs to be added to the vcxproj file in Common.

@void-ghost void-ghost force-pushed the savestate_race_condition_fix branch 4 times, most recently from 30b3f78 to 173df73 Compare September 26, 2015 22:14
@@ -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.


//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.

@void-ghost void-ghost force-pushed the savestate_race_condition_fix branch 2 times, most recently from 7916b99 to aceba9e Compare September 27, 2015 18:26
…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.
@JosJuice
Copy link
Member

LGTM.

shuffle2 added a commit that referenced this pull request Oct 4, 2015
SaveState: Fix for race condition in SaveAs(...)
@shuffle2 shuffle2 merged commit b926061 into dolphin-emu:master Oct 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants