Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite waitable atomics #9117

Merged
merged 8 commits into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion Utilities/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,17 @@ void thread_base::initialize(void (*error_cb)(), bool(*wait_cb)(const void*))
void thread_base::notify_abort() noexcept
{
m_signal.try_inc();
atomic_storage_futex::raw_notify(+m_state_notifier);

while (auto ptr = m_state_notifier.load())
{
// Since this function is not perfectly implemented, run it in a loop
atomic_storage_futex::raw_notify(ptr);

if (m_state_notifier.load() == ptr)
{
break;
}
}
}

bool thread_base::finalize(thread_state result_state) noexcept
Expand Down
1 change: 1 addition & 0 deletions Utilities/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class named_thread final : public Context, result_storage_t<Context>, thread_bas

if (_this->m_state >= thread_state::aborting)
{
_this->m_state_notifier.store(data);
return false;
}

Expand Down
6 changes: 6 additions & 0 deletions Utilities/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ DYNAMIC_IMPORT("ntdll.dll", NtWaitForKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOO
DYNAMIC_IMPORT("ntdll.dll", NtReleaseKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
DYNAMIC_IMPORT("ntdll.dll", NtWaitForSingleObject, NTSTATUS(HANDLE Handle, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
DYNAMIC_IMPORT("ntdll.dll", NtDelayExecution, NTSTATUS(BOOLEAN Alertable, PLARGE_INTEGER DelayInterval));
DYNAMIC_IMPORT("ntdll.dll", NtWaitForAlertByThreadId, NTSTATUS(PVOID Address, PLARGE_INTEGER Timeout));
DYNAMIC_IMPORT("ntdll.dll", NtAlertThreadByThreadId, NTSTATUS(DWORD_PTR ThreadId));

constexpr NTSTATUS NTSTATUS_SUCCESS = 0;
constexpr NTSTATUS NTSTATUS_ALERTED = 0x101;
constexpr NTSTATUS NTSTATUS_TIMEOUT = 0x102;
#endif

#ifndef __linux__
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/RawSPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inline void try_start(spu_thread& spu)
}).second)
{
spu.state -= cpu_flag::stop;
thread_ctrl::raw_notify(static_cast<named_thread<spu_thread>&>(spu));
thread_ctrl::notify(static_cast<named_thread<spu_thread>&>(spu));
}
};

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/SPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3646,7 +3646,7 @@ bool spu_thread::stop_and_signal(u32 code)

if (thread.get() != this)
{
thread_ctrl::raw_notify(*thread);
thread_ctrl::notify(*thread);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/lv2/sys_spu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ error_code sys_spu_thread_group_start(ppu_thread& ppu, u32 id)
if (thread && ran_threads--)
{
thread->state -= cpu_flag::stop;
thread_ctrl::raw_notify(*thread);
thread_ctrl::notify(*thread);
}
}

Expand Down Expand Up @@ -906,7 +906,7 @@ error_code sys_spu_thread_group_resume(ppu_thread& ppu, u32 id)
if (thread)
{
thread->state -= cpu_flag::suspend;
thread_ctrl::raw_notify(*thread);
thread_ctrl::notify(*thread);
}
}

Expand Down Expand Up @@ -1915,7 +1915,7 @@ error_code sys_isolated_spu_create(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<voi
return CELL_OK;
}

template <bool isolated = false>
template <bool isolated = false>
error_code raw_spu_destroy(ppu_thread& ppu, u32 id)
{
const u32 idm_id = spu_thread::find_raw_spu(id);
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/perf_meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void perf_stat_base::print(const char* name) noexcept
{
if (u64 count = m_log[i + 1].load())
{
perf_log.notice("Perf stats for %s: events < %.3fµs: %u", name, std::pow(2., i) / 1000., count);
perf_log.notice(u8"Perf stats for %s: events < %.3fµs: %u", name, std::pow(2., i) / 1000., count);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/perf_meter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class perf_meter
// Print in microseconds
if (static_cast<u64>(diff * 1000'000.) >= g_cfg.core.perf_report_threshold)
{
perf_log.notice("%s: %.3fµs", perf_name<ShortName>.data(), diff * 1000'000.);
perf_log.notice(u8"%s: %.3fµs", perf_name<ShortName>.data(), diff * 1000'000.);
}

// TODO: handle push(), currently ignored
Expand Down