Skip to content

Commit

Permalink
LV2: Avoid using multi-variable atomic waiting on cpu_thread::state wait
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Sep 21, 2022
1 parent 142ad02 commit 1fee040
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions rpcs3/Emu/CPU/CPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ void cpu_thread::operator()()
continue;
}

thread_ctrl::wait_on(state, state0);
state.wait(state0);

if (state & cpu_flag::ret && state.test_and_reset(cpu_flag::ret))
{
Expand Down Expand Up @@ -640,7 +640,7 @@ cpu_thread::cpu_thread(u32 id)

void cpu_thread::cpu_wait(bs_t<cpu_flag> old)
{
thread_ctrl::wait_on(state, old);
state.wait(old);
}

static atomic_t<u32> s_dummy_atomic = 0;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString,
break;
}

thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}

if (is_blocking)
Expand Down
5 changes: 4 additions & 1 deletion rpcs3/Emu/Cell/SPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,10 @@ void spu_thread::cleanup()
vm::free_range_lock(range_lock);

// Signal the debugger about the termination
state += cpu_flag::exit;
if (!state.test_and_set(cpu_flag::exit))
{
state.notify_one();
}
}

spu_thread::~spu_thread()
Expand Down
6 changes: 5 additions & 1 deletion rpcs3/Emu/Cell/lv2/lv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,9 +1605,13 @@ void lv2_obj::schedule_all(u64 current_time)
if (target->state & cpu_flag::suspend)
{
ppu_log.trace("schedule(): %s", target->id);
target->state.atomic_op(FN(x += cpu_flag::signal, x -= cpu_flag::suspend));
target->start_time = 0;

if ((target->state.fetch_op(FN(x += cpu_flag::signal, x -= cpu_flag::suspend, void())) & (cpu_flag::wait + cpu_flag::signal)) != cpu_flag::wait)
{
continue;
}

if (notify_later_idx == std::size(g_to_notify))
{
// Out of notification slots, notify locally (resizable container is not worth it)
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ error_code sys_cond_wait(ppu_thread& ppu, u32 cond_id, u64 timeout)
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ error_code sys_event_queue_receive(ppu_thread& ppu, u32 equeue_id, vm::ptr<sys_e
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_event_flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ error_code sys_event_flag_wait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_lwcond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ error_code _sys_lwcond_queue_wait(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ error_code _sys_lwmutex_lock(ppu_thread& ppu, u32 lwmutex_id, u64 timeout)
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ error_code sys_mutex_lock(ppu_thread& ppu, u32 mutex_id, u64 timeout)
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
12 changes: 6 additions & 6 deletions rpcs3/Emu/Cell/lv2/sys_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ error_code sys_net_bnet_accept(ppu_thread& ppu, s32 s, vm::ptr<sys_net_sockaddr>
break;
}

thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}

if (ppu.gpr[3] == static_cast<u64>(-SYS_NET_EINTR))
Expand Down Expand Up @@ -579,7 +579,7 @@ error_code sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptr<sys_net_sockaddr
break;
}

thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}

if (ppu.gpr[3] == static_cast<u64>(-SYS_NET_EINTR))
Expand Down Expand Up @@ -858,7 +858,7 @@ error_code sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr<void> buf, u32
break;
}

thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}

if (ppu.gpr[3] == static_cast<u64>(-SYS_NET_EINTR))
Expand Down Expand Up @@ -979,7 +979,7 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr<void> buf, u32 l
{
break;
}
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}

if (ppu.gpr[3] == static_cast<u64>(-SYS_NET_EINTR))
Expand Down Expand Up @@ -1332,7 +1332,7 @@ error_code sys_net_bnet_poll(ppu_thread& ppu, vm::ptr<sys_net_pollfd> fds, s32 n
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down Expand Up @@ -1572,7 +1572,7 @@ error_code sys_net_bnet_select(ppu_thread& ppu, s32 nfds, vm::ptr<sys_net_fd_set
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void _sys_process_exit(ppu_thread& ppu, s32 status, u32 arg2, u32 arg3)
break;
}

thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down Expand Up @@ -472,7 +472,7 @@ void _sys_process_exit2(ppu_thread& ppu, s32 status, vm::ptr<sys_exit2_param> ar
break;
}

thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_rwlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ error_code sys_rwlock_rlock(ppu_thread& ppu, u32 rw_lock_id, u64 timeout)
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down Expand Up @@ -471,7 +471,7 @@ error_code sys_rwlock_wlock(ppu_thread& ppu, u32 rw_lock_id, u64 timeout)
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ error_code sys_semaphore_wait(ppu_thread& ppu, u32 sem_id, u64 timeout)
}
else
{
thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_spu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ error_code sys_spu_thread_group_join(ppu_thread& ppu, u32 id, vm::ptr<u32> cause
break;
}

thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}
}
while (false);
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_usbd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ error_code sys_usbd_receive_event(ppu_thread& ppu, u32 handle, vm::ptr<u64> arg1
break;
}

thread_ctrl::wait_on(ppu.state, state);
ppu.state.wait(state);
}

*arg1 = ppu.gpr[4];
Expand Down

0 comments on commit 1fee040

Please sign in to comment.