Skip to content

Commit

Permalink
Progress Dialog: Fix race that could lead to ever-inaccurate results
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Aug 22, 2023
1 parent a001e6e commit bbe00f0
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions rpcs3/Emu/system_progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,22 @@ void progress_dialog_server::operator()()
// Update progress
while (!g_system_progress_stopping && thread_ctrl::state() != thread_state::aborting)
{
const auto text_new = +g_progr.load();
auto whole_state = std::make_tuple(+g_progr.load(), +g_progr_ftotal, +g_progr_fdone, +g_progr_ptotal, +g_progr_pdone);

const u32 ftotal_new = g_progr_ftotal;
const u32 fdone_new = g_progr_fdone;
const u32 ptotal_new = g_progr_ptotal;
const u32 pdone_new = g_progr_pdone;
while (true)
{
const auto new_state = std::make_tuple(+g_progr.load(), +g_progr_ftotal, +g_progr_fdone, +g_progr_ptotal, +g_progr_pdone);

if (new_state != whole_state)
{
// Only leave while it has a complete (atomic) state
break;
}

whole_state = new_state;
}

const auto [text_new, ftotal_new, fdone_new, ptotal_new, pdone_new] = whole_state;

if (ftotal != ftotal_new || fdone != fdone_new || ptotal != ptotal_new || pdone != pdone_new || text_new != text1)
{
Expand All @@ -137,8 +147,8 @@ void progress_dialog_server::operator()()

if (!text_new)
{
// Close dialog
break;
// Incomplete state
continue;
}

if (show_overlay_message)
Expand Down Expand Up @@ -182,6 +192,12 @@ void progress_dialog_server::operator()()
});
}
}
// Leave only if total count is equal to done count
else if (ftotal == fdone && ptotal == pdone && !text_new)
{
// Complete state, empty message
break;
}

if (show_overlay_message)
{
Expand Down

0 comments on commit bbe00f0

Please sign in to comment.