1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

Implement cellMsgDialog closing thread

Fixing deprecation warning.
This commit is contained in:
Nekotekina 2020-02-22 14:46:49 +03:00
parent 3001701059
commit 96be40bf30

View File

@ -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)
{
@ -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;
@ -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();
}
@ -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();
@ -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;
}
@ -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;
}
@ -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