Skip to content

Commit 7cb2977

Browse files
committed
Emu: Run Qt events while calling Emu.Cleanup
1 parent cb5fd17 commit 7cb2977

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

rpcs3/Emu/System.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,6 +3895,40 @@ bool Emulator::Quit(bool force_quit)
38953895

38963896
void Emulator::CleanUp()
38973897
{
3898+
// Signal threads
3899+
if (auto rsx = g_fxo->try_get<rsx::thread>())
3900+
{
3901+
*static_cast<cpu_thread*>(rsx) = thread_state::aborting;
3902+
}
3903+
3904+
for (const auto& [type, data] : *g_fxo)
3905+
{
3906+
if (type.thread_op)
3907+
{
3908+
type.thread_op(data, thread_state::aborting);
3909+
}
3910+
}
3911+
3912+
// Join threads
3913+
qt_events_aware_op(50, [&]()
3914+
{
3915+
bool has_running = false;
3916+
3917+
for (const auto& [type, data] : *g_fxo)
3918+
{
3919+
if (type.thread_op)
3920+
{
3921+
if (type.thread_op(data, thread_state::aborting) != thread_state::finished)
3922+
{
3923+
has_running = true;
3924+
break;
3925+
}
3926+
}
3927+
}
3928+
3929+
return has_running == false;
3930+
});
3931+
38983932
// Deinitialize object manager to prevent any hanging objects at program exit
38993933
g_fxo->clear();
39003934
}

rpcs3/util/fixed_typemap.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace stx
7171
struct typeinfo
7272
{
7373
bool(*create)(uchar* ptr, manual_typemap&, utils::serial*, std::string_view) noexcept = nullptr;
74-
void(*thread_op)(void* ptr, thread_state) noexcept = nullptr;
74+
thread_state(*thread_op)(void* ptr, thread_state) noexcept = nullptr;
7575
void(*save)(void* ptr, utils::serial&) noexcept = nullptr;
7676
bool(*saveable)(bool) noexcept = nullptr;
7777
void(*destroy)(void* ptr) noexcept = nullptr;
@@ -137,10 +137,20 @@ namespace stx
137137
}
138138

139139
template <typename T>
140-
static void call_thread_op(void* ptr, thread_state state) noexcept
140+
static thread_state call_thread_op(void* ptr, thread_state state) noexcept
141141
{
142142
// Abort and/or join (expected thread_state::aborting or thread_state::finished)
143143
*std::launder(static_cast<T*>(ptr)) = state;
144+
145+
if constexpr (std::is_convertible_v<const T&, thread_state>)
146+
{
147+
return *std::launder(static_cast<T*>(ptr));
148+
}
149+
else
150+
{
151+
constexpr thread_state context_finished{3};
152+
return context_finished;
153+
}
144154
}
145155

146156
template <typename T>

0 commit comments

Comments
 (0)