Skip to content

Commit

Permalink
Make more use of the new atomic_t<>::release
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 authored and Nekotekina committed Feb 9, 2019
1 parent e3ee481 commit 0861226
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
14 changes: 8 additions & 6 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,17 +1092,18 @@ extern bool ppu_stwcx(ppu_thread& ppu, u32 addr, u32 reg_value)
vm::passive_unlock(ppu);

auto& res = vm::reservation_lock(addr, sizeof(u32));
const u64 old_time = res.load() & ~1ull;

const bool result = ppu.rtime == (res & ~1ull) && data.compare_and_swap_test(old_data, reg_value);
const bool result = ppu.rtime == old_time && data.compare_and_swap_test(old_data, reg_value);

if (result)
{
res++;
res.release(old_time + 2);
vm::reservation_notifier(addr, sizeof(u32)).notify_all();
}
else
{
res &= ~1ull;
res.release(old_time);
}

vm::passive_lock(ppu);
Expand Down Expand Up @@ -1185,17 +1186,18 @@ extern bool ppu_stdcx(ppu_thread& ppu, u32 addr, u64 reg_value)
vm::passive_unlock(ppu);

auto& res = vm::reservation_lock(addr, sizeof(u64));
const u64 old_time = res.load() & ~1ull;

const bool result = ppu.rtime == (res & ~1ull) && data.compare_and_swap_test(old_data, reg_value);
const bool result = ppu.rtime == old_time && data.compare_and_swap_test(old_data, reg_value);

if (result)
{
res++;
res.release(old_time + 2);
vm::reservation_notifier(addr, sizeof(u64)).notify_all();
}
else
{
res &= ~1ull;
res.release(old_time);
}

vm::passive_lock(ppu);
Expand Down
54 changes: 28 additions & 26 deletions rpcs3/Emu/Cell/SPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,20 @@ void spu_thread::cpu_init()
ch_tag_upd = 0;
ch_tag_mask = 0;
mfc_prxy_mask = 0;
ch_tag_stat.data.store({});
ch_tag_stat.data.release({});
ch_stall_mask = 0;
ch_stall_stat.data.store({});
ch_atomic_stat.data.store({});
ch_stall_stat.data.release({});
ch_atomic_stat.data.release({});

ch_in_mbox.clear();

ch_out_mbox.data.store({});
ch_out_intr_mbox.data.store({});
ch_out_mbox.data.release({});
ch_out_intr_mbox.data.release({});

snr_config = 0;

ch_snr1.data.store({});
ch_snr2.data.store({});
ch_snr1.data.release({});
ch_snr2.data.release({});

ch_event_mask = 0;
ch_event_stat = 0;
Expand All @@ -494,9 +494,9 @@ void spu_thread::cpu_init()
ch_dec_start_timestamp = get_timebased_time(); // ???
ch_dec_value = 0;

run_ctrl = 0;
status = 0;
npc = 0;
run_ctrl.release(0);
status.release(0);
npc.release(0);

int_ctrl[0].clear();
int_ctrl[1].clear();
Expand Down Expand Up @@ -810,28 +810,28 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args)
{
auto& res = vm::reservation_lock(eal, 1);
*reinterpret_cast<u8*>(dst) = *reinterpret_cast<const u8*>(src);
res++;
res.release(res.load() + 1);
break;
}
case 2:
{
auto& res = vm::reservation_lock(eal, 2);
*reinterpret_cast<u16*>(dst) = *reinterpret_cast<const u16*>(src);
res++;
res.release(res.load() + 1);
break;
}
case 4:
{
auto& res = vm::reservation_lock(eal, 4);
*reinterpret_cast<u32*>(dst) = *reinterpret_cast<const u32*>(src);
res++;
res.release(res.load() + 1);
break;
}
case 8:
{
auto& res = vm::reservation_lock(eal, 8);
*reinterpret_cast<u64*>(dst) = *reinterpret_cast<const u64*>(src);
res++;
res.release(res.load() + 1);
break;
}
default:
Expand All @@ -850,7 +850,7 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args)
size -= 16;
}

res++;
res.release(res.load() + 1);
break;
}

Expand All @@ -874,7 +874,7 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args)
size -= 16;
}

*lock = 0;
lock->release(0);
break;
}
}
Expand Down Expand Up @@ -1086,12 +1086,12 @@ void spu_thread::do_putlluc(const spu_mfc_cmd& args)
// TODO: vm::check_addr
vm::writer_lock lock(addr);
mov_rdata(data.data(), to_write.data());
res++;
res.release(res.load() + 1);
}
else
{
mov_rdata(data.data(), to_write.data());
res++;
res.release(res.load() + 1);
}
}

Expand Down Expand Up @@ -1281,6 +1281,7 @@ bool spu_thread::process_mfc_cmd()
else
{
auto& res = vm::reservation_lock(addr, 128);
const u64 old_time = res.load() & ~1ull;

if (g_cfg.core.spu_accurate_getllar)
{
Expand All @@ -1290,15 +1291,15 @@ bool spu_thread::process_mfc_cmd()
// TODO: vm::check_addr
vm::writer_lock lock(addr);

ntime = res & ~1ull;
ntime = old_time;
mov_rdata(dst.data(), data.data());
res &= ~1ull;
res.release(old_time);
}
else
{
ntime = res & ~1ull;
ntime = old_time;
mov_rdata(dst.data(), data.data());
res &= ~1ull;
res.release(old_time);
}
}

Expand Down Expand Up @@ -1355,8 +1356,9 @@ bool spu_thread::process_mfc_cmd()
else if (auto& data = vm::_ref<decltype(rdata)>(addr); rdata == data)
{
auto& res = vm::reservation_lock(raddr, 128);
const u64 old_time = res.load() & ~1ull;

if (rtime == (res & ~1ull))
if (rtime == old_time)
{
*reinterpret_cast<atomic_t<u32>*>(&data) += 0;

Expand All @@ -1367,17 +1369,17 @@ bool spu_thread::process_mfc_cmd()
if (rdata == data)
{
mov_rdata(data.data(), to_write.data());
res++;
res.release(old_time + 2);
result = 1;
}
else
{
res &= ~1ull;
res.release(old_time);
}
}
else
{
res &= ~1ull;
res.release(old_time);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Emu/Cell/SPUThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ struct spu_channel_4_t
public:
void clear()
{
values.store({});
value3 = 0;
values.release({});
value3.release(0);
}

// push unconditionally (overwriting latest value), returns true if needs signaling
Expand Down Expand Up @@ -364,8 +364,8 @@ struct spu_int_ctrl_t

void clear()
{
mask = 0;
stat = 0;
mask.release(0);
stat.release(0);
tag = nullptr;
}
};
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 @@ -266,7 +266,7 @@ error_code _sys_lwcond_queue_wait(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id
return cpu;
}

mutex->signaled = 1;
mutex->signaled.release(1);
return nullptr;
});

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 @@ -175,7 +175,7 @@ error_code _sys_lwmutex_unlock(ppu_thread& ppu, u32 lwmutex_id)
return cpu;
}

mutex.signaled = 1;
mutex.signaled.release(1);
return nullptr;
});

Expand Down

0 comments on commit 0861226

Please sign in to comment.