1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Add logging for CallFromMainThread

This commit is contained in:
Eladash 2024-03-24 09:38:26 +02:00 committed by Elad Ashkenazi
parent e32ed90d21
commit 213a19c9f3
4 changed files with 29 additions and 14 deletions

View File

@ -218,6 +218,11 @@ public:
// Get current thread name
static std::string get_name()
{
if (!g_tls_this_thread)
{
return "not named_thread";
}
return *g_tls_this_thread->m_tname.load();
}

View File

@ -5253,7 +5253,7 @@ s64 spu_thread::get_ch_value(u32 ch)
}
}
const bool seed = (utils::get_tsc() >> 8) % 100;
const usz seed = (utils::get_tsc() >> 8) % 100;
#ifdef __linux__
const bool reservation_busy_waiting = false;

View File

@ -161,17 +161,16 @@ void fmt_class_string<cfg_mode>::format(std::string& out, u64 arg)
});
}
void Emulator::CallFromMainThread(std::function<void()>&& func, atomic_t<u32>* wake_up, bool track_emu_state, u64 stop_ctr) const
void Emulator::CallFromMainThread(std::function<void()>&& func, atomic_t<u32>* wake_up, bool track_emu_state, u64 stop_ctr, u32 line, u32 col, const char* file, const char* fun) const
{
if (!track_emu_state)
std::function<void()> final_func = [this, before = IsStopped(), track_emu_state, thread_name = thread_ctrl::get_name(), src = src_loc{line, col, file, fun}
, count = (stop_ctr == umax ? +m_stop_ctr : stop_ctr), func = std::move(func)]
{
m_cb.call_from_main_thread(std::move(func), wake_up);
return;
}
const bool call_it = (!track_emu_state || (count == m_stop_ctr && before == IsStopped()));
std::function<void()> final_func = [this, before = IsStopped(), count = (stop_ctr == umax ? +m_stop_ctr : stop_ctr), func = std::move(func)]
{
if (count == m_stop_ctr && before == IsStopped())
sys_log.trace("Callback from thread '%s' at [%s] is %s", thread_name, src, call_it ? "called" : "skipped");
if (call_it)
{
func();
}
@ -184,14 +183,17 @@ void Emulator::BlockingCallFromMainThread(std::function<void()>&& func, u32 line
{
atomic_t<u32> wake_up = 0;
CallFromMainThread(std::move(func), &wake_up);
sys_log.trace("Blocking Callback from thread '%s' at [%s] is queued", thread_ctrl::get_name(), src_loc{line, col, file, fun});
CallFromMainThread(std::move(func), &wake_up, true, umax, line, col, file, fun);
while (!wake_up)
{
if (!thread_ctrl::get_current())
{
fmt::throw_exception("Current thread null while calling BlockingCallFromMainThread from %s", src_loc{line, col, file, fun});
fmt::throw_exception("Calling thread of BlockingCallFromMainThread is not of named_thread<>, calling from %s", src_loc{line, col, file, fun});
}
wake_up.wait(0);
}
}

View File

@ -183,7 +183,11 @@ public:
}
// Call from the GUI thread
void CallFromMainThread(std::function<void()>&& func, atomic_t<u32>* wake_up = nullptr, bool track_emu_state = true, u64 stop_ctr = umax) const;
void CallFromMainThread(std::function<void()>&& func, atomic_t<u32>* wake_up = nullptr, bool track_emu_state = true, u64 stop_ctr = umax,
u32 line = __builtin_LINE(),
u32 col = __builtin_COLUMN(),
const char* file = __builtin_FILE(),
const char* fun = __builtin_FUNCTION()) const;
// Blocking call from the GUI thread
void BlockingCallFromMainThread(std::function<void()>&& func,
@ -200,9 +204,13 @@ public:
return stop_counter_t{+m_stop_ctr};
}
void CallFromMainThread(std::function<void()>&& func, stop_counter_t counter) const
void CallFromMainThread(std::function<void()>&& func, stop_counter_t counter,
u32 line = __builtin_LINE(),
u32 col = __builtin_COLUMN(),
const char* file = __builtin_FILE(),
const char* fun = __builtin_FUNCTION()) const
{
CallFromMainThread(std::move(func), nullptr, true, static_cast<u64>(counter));
CallFromMainThread(std::move(func), nullptr, true, static_cast<u64>(counter), line, col, file, fun);
}
void PostponeInitCode(std::function<void()>&& func)