Skip to content

Commit

Permalink
Savestates: Fix rare race
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Apr 13, 2024
1 parent e45cbc1 commit b72bfb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
8 changes: 8 additions & 0 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3318,6 +3318,14 @@ void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_s

set_progress_message("Commiting File");

fs::file to_close_file;
{
auto reset = init_mtx->reset();
to_close_file = std::move(file.file);
reset.set_init();
}
to_close_file.close();

if (!file.commit() || !fs::get_stat(path, file_stat))
{
sys_log.error("Failed to write savestate to file! (path='%s', %s)", path, fs::g_tls_error);
Expand Down
26 changes: 20 additions & 6 deletions rpcs3/rpcs3qt/gui_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,25 +709,39 @@ void gui_application::InitializeCallbacks()
std::string verbose_message;
usz bytes_written = 0;

while (true)
{
auto init = static_cast<stx::init_mutex*>(init_mtx.get())->access();
auto mtx = static_cast<stx::init_mutex*>(init_mtx.get());
auto init = mtx->access();

if (!init)
{
pdlg->reject();
return;
// Try to wait for the abort process to complete
auto fake_reset = mtx->reset();
if (!fake_reset)
{
// End of emulation termination
pdlg->reject();
return;
}

fake_reset.set_init();

// Now ar_ptr contains a null file descriptor
continue;
}

if (auto str_ptr = code_location->load())
{
verbose_message = "\n" + *str_ptr;
}

*half_seconds += 1;

bytes_written = ar_ptr->get_size();
bytes_written = std::max<usz>(ar_ptr->get_size(), old_written);
break;
}

*half_seconds += 1;

if (old_written == bytes_written)
{
if (repeat_count == 60)
Expand Down

0 comments on commit b72bfb1

Please sign in to comment.