Skip to content

Commit

Permalink
Implement cellMsgDialog closing thread
Browse files Browse the repository at this point in the history
Fixing deprecation warning.
  • Loading branch information
Nekotekina committed Feb 22, 2020
1 parent e49777d commit bf0744d
Showing 1 changed file with 66 additions and 29 deletions.
95 changes: 66 additions & 29 deletions rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

LOG_CHANNEL(cellSysutil);

extern u64 get_guest_system_time();

template<>
void fmt_class_string<CellMsgDialogError>::format(std::string& out, u64 arg)
{
Expand Down Expand Up @@ -79,6 +81,59 @@ struct msg_info
}
};

struct msg_dlg_thread_info
{
atomic_t<u64> wait_until = 0;

void operator()()
{
while (thread_ctrl::state() != thread_state::aborting)
{
const u64 new_value = wait_until.load();

if (new_value == 0)
{
wait_until.wait(0);
continue;
}

while (get_guest_system_time() < new_value)
{
if (wait_until.load() != new_value)
break;

std::this_thread::sleep_for(10ms);
}

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
if (!wait_until.compare_and_swap_test(new_value, 0))
{
continue;
}

dlg->close();
}
}
else if (const auto dlg = g_fxo->get<msg_info>()->get())
{
if (!wait_until.compare_and_swap_test(new_value, 0))
{
continue;
}

dlg->on_close(CELL_MSGDIALOG_BUTTON_NONE);
}
}
}

static constexpr auto thread_name = "MsgDialog Close Thread"sv;
};

using msg_dlg_thread = named_thread<msg_dlg_thread_info>;

// variable used to immediately get the response from auxiliary message dialogs (callbacks would be async)
atomic_t<s32> g_last_user_response = CELL_MSGDIALOG_BUTTON_NONE;

Expand Down Expand Up @@ -140,6 +195,7 @@ error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString,
});
}

g_fxo->get<msg_dlg_thread>()->wait_until = 0;
g_fxo->get<msg_info>()->remove();
}

Expand Down Expand Up @@ -368,31 +424,19 @@ error_code cellMsgDialogClose(f32 delay)
{
cellSysutil.warning("cellMsgDialogClose(delay=%f)", delay);

extern u64 get_guest_system_time();
const u64 wait_until = get_guest_system_time() + static_cast<s64>(std::max<float>(delay, 0.0f) * 1000);

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
thread_ctrl::spawn("cellMsgDialogClose() Thread", [=]
{
while (get_guest_system_time() < wait_until)
{
if (Emu.IsStopped())
return;

if (manager->get<rsx::overlays::message_dialog>() != dlg)
return;

std::this_thread::sleep_for(1ms);
}

dlg->close();
});

const auto thr = g_fxo->get<msg_dlg_thread>();
thr->wait_until = wait_until;
thr->wait_until.notify_one();
return CELL_OK;
}

return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED;
}

const auto dlg = g_fxo->get<msg_info>()->get();
Expand All @@ -402,18 +446,9 @@ error_code cellMsgDialogClose(f32 delay)
return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED;
}

thread_ctrl::spawn("cellMsgDialogClose() Thread", [=]()
{
while (dlg->state == MsgDialogState::Open && get_guest_system_time() < wait_until)
{
if (Emu.IsStopped()) return;

std::this_thread::sleep_for(1ms);
}

dlg->on_close(CELL_MSGDIALOG_BUTTON_NONE);
});

const auto thr = g_fxo->get<msg_dlg_thread>();
thr->wait_until = wait_until;
thr->wait_until.notify_one();
return CELL_OK;
}

Expand All @@ -425,6 +460,7 @@ error_code cellMsgDialogAbort()
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
g_fxo->get<msg_dlg_thread>()->wait_until = 0;
dlg->close(false);
return CELL_OK;
}
Expand All @@ -442,6 +478,7 @@ error_code cellMsgDialogAbort()
return CELL_SYSUTIL_ERROR_BUSY;
}

g_fxo->get<msg_dlg_thread>()->wait_until = 0;
g_fxo->get<msg_info>()->remove(); // this shouldn't call on_close
pad::SetIntercepted(false); // so we need to reenable the pads here

Expand Down

0 comments on commit bf0744d

Please sign in to comment.