Skip to content

Commit

Permalink
Implement thread_ctrl::wait_on (see #9208)
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 authored and Nekotekina committed Jan 21, 2021
1 parent f816742 commit 12e1be2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Utilities/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ class thread_ctrl final
_wait_for(-1, true);
}

// Wait for both thread sync var and provided atomic var
template <typename T, atomic_wait::op op = atomic_wait::op::eq, typename U>
static inline void wait_on(T& wait, U old, u64 usec = -1)
{
auto _this = g_tls_this_thread;

if (_this->m_sync.bit_test_reset(2))
{
return;
}

atomic_wait::list<2> list{};
list.set<0, op>(wait, old);
list.set<1>(_this->m_sync, 0, 4 + 1);
list.wait(atomic_wait_timeout{usec <= 0xffff'ffff'ffff'ffff / 1000 ? usec * 1000 : 0xffff'ffff'ffff'ffff});
}

// Exit.
[[noreturn]] static void emergency_exit(std::string_view reason);

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void _sys_ppu_thread_exit(ppu_thread& ppu, u64 errorcode)
if (old_status == ppu_join_status::joinable)
{
// Wait for termination
ppu.joiner.wait(ppu_join_status::zombie);
thread_ctrl::wait_on(ppu.joiner, ppu_join_status::zombie);
}

ppu_thread_exit(ppu);
Expand Down

0 comments on commit 12e1be2

Please sign in to comment.