Make more use of the new atomic_t<>::release

This commit is contained in:
eladash 2019-02-09 11:34:36 +02:00 committed by Ivan
parent e3ee481f01
commit 0861226271
5 changed files with 42 additions and 38 deletions

View file

@ -1092,17 +1092,18 @@ extern bool ppu_stwcx(ppu_thread& ppu, u32 addr, u32 reg_value)
vm::passive_unlock(ppu); vm::passive_unlock(ppu);
auto& res = vm::reservation_lock(addr, sizeof(u32)); 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) if (result)
{ {
res++; res.release(old_time + 2);
vm::reservation_notifier(addr, sizeof(u32)).notify_all(); vm::reservation_notifier(addr, sizeof(u32)).notify_all();
} }
else else
{ {
res &= ~1ull; res.release(old_time);
} }
vm::passive_lock(ppu); vm::passive_lock(ppu);
@ -1185,17 +1186,18 @@ extern bool ppu_stdcx(ppu_thread& ppu, u32 addr, u64 reg_value)
vm::passive_unlock(ppu); vm::passive_unlock(ppu);
auto& res = vm::reservation_lock(addr, sizeof(u64)); 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) if (result)
{ {
res++; res.release(old_time + 2);
vm::reservation_notifier(addr, sizeof(u64)).notify_all(); vm::reservation_notifier(addr, sizeof(u64)).notify_all();
} }
else else
{ {
res &= ~1ull; res.release(old_time);
} }
vm::passive_lock(ppu); vm::passive_lock(ppu);

View file

@ -471,20 +471,20 @@ void spu_thread::cpu_init()
ch_tag_upd = 0; ch_tag_upd = 0;
ch_tag_mask = 0; ch_tag_mask = 0;
mfc_prxy_mask = 0; mfc_prxy_mask = 0;
ch_tag_stat.data.store({}); ch_tag_stat.data.release({});
ch_stall_mask = 0; ch_stall_mask = 0;
ch_stall_stat.data.store({}); ch_stall_stat.data.release({});
ch_atomic_stat.data.store({}); ch_atomic_stat.data.release({});
ch_in_mbox.clear(); ch_in_mbox.clear();
ch_out_mbox.data.store({}); ch_out_mbox.data.release({});
ch_out_intr_mbox.data.store({}); ch_out_intr_mbox.data.release({});
snr_config = 0; snr_config = 0;
ch_snr1.data.store({}); ch_snr1.data.release({});
ch_snr2.data.store({}); ch_snr2.data.release({});
ch_event_mask = 0; ch_event_mask = 0;
ch_event_stat = 0; ch_event_stat = 0;
@ -494,9 +494,9 @@ void spu_thread::cpu_init()
ch_dec_start_timestamp = get_timebased_time(); // ??? ch_dec_start_timestamp = get_timebased_time(); // ???
ch_dec_value = 0; ch_dec_value = 0;
run_ctrl = 0; run_ctrl.release(0);
status = 0; status.release(0);
npc = 0; npc.release(0);
int_ctrl[0].clear(); int_ctrl[0].clear();
int_ctrl[1].clear(); int_ctrl[1].clear();
@ -810,28 +810,28 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args)
{ {
auto& res = vm::reservation_lock(eal, 1); auto& res = vm::reservation_lock(eal, 1);
*reinterpret_cast<u8*>(dst) = *reinterpret_cast<const u8*>(src); *reinterpret_cast<u8*>(dst) = *reinterpret_cast<const u8*>(src);
res++; res.release(res.load() + 1);
break; break;
} }
case 2: case 2:
{ {
auto& res = vm::reservation_lock(eal, 2); auto& res = vm::reservation_lock(eal, 2);
*reinterpret_cast<u16*>(dst) = *reinterpret_cast<const u16*>(src); *reinterpret_cast<u16*>(dst) = *reinterpret_cast<const u16*>(src);
res++; res.release(res.load() + 1);
break; break;
} }
case 4: case 4:
{ {
auto& res = vm::reservation_lock(eal, 4); auto& res = vm::reservation_lock(eal, 4);
*reinterpret_cast<u32*>(dst) = *reinterpret_cast<const u32*>(src); *reinterpret_cast<u32*>(dst) = *reinterpret_cast<const u32*>(src);
res++; res.release(res.load() + 1);
break; break;
} }
case 8: case 8:
{ {
auto& res = vm::reservation_lock(eal, 8); auto& res = vm::reservation_lock(eal, 8);
*reinterpret_cast<u64*>(dst) = *reinterpret_cast<const u64*>(src); *reinterpret_cast<u64*>(dst) = *reinterpret_cast<const u64*>(src);
res++; res.release(res.load() + 1);
break; break;
} }
default: default:
@ -850,7 +850,7 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args)
size -= 16; size -= 16;
} }
res++; res.release(res.load() + 1);
break; break;
} }
@ -874,7 +874,7 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args)
size -= 16; size -= 16;
} }
*lock = 0; lock->release(0);
break; break;
} }
} }
@ -1086,12 +1086,12 @@ void spu_thread::do_putlluc(const spu_mfc_cmd& args)
// TODO: vm::check_addr // TODO: vm::check_addr
vm::writer_lock lock(addr); vm::writer_lock lock(addr);
mov_rdata(data.data(), to_write.data()); mov_rdata(data.data(), to_write.data());
res++; res.release(res.load() + 1);
} }
else else
{ {
mov_rdata(data.data(), to_write.data()); mov_rdata(data.data(), to_write.data());
res++; res.release(res.load() + 1);
} }
} }
@ -1281,6 +1281,7 @@ bool spu_thread::process_mfc_cmd()
else else
{ {
auto& res = vm::reservation_lock(addr, 128); auto& res = vm::reservation_lock(addr, 128);
const u64 old_time = res.load() & ~1ull;
if (g_cfg.core.spu_accurate_getllar) if (g_cfg.core.spu_accurate_getllar)
{ {
@ -1290,15 +1291,15 @@ bool spu_thread::process_mfc_cmd()
// TODO: vm::check_addr // TODO: vm::check_addr
vm::writer_lock lock(addr); vm::writer_lock lock(addr);
ntime = res & ~1ull; ntime = old_time;
mov_rdata(dst.data(), data.data()); mov_rdata(dst.data(), data.data());
res &= ~1ull; res.release(old_time);
} }
else else
{ {
ntime = res & ~1ull; ntime = old_time;
mov_rdata(dst.data(), data.data()); mov_rdata(dst.data(), data.data());
res &= ~1ull; res.release(old_time);
} }
} }
@ -1355,8 +1356,9 @@ bool spu_thread::process_mfc_cmd()
else if (auto& data = vm::_ref<decltype(rdata)>(addr); rdata == data) else if (auto& data = vm::_ref<decltype(rdata)>(addr); rdata == data)
{ {
auto& res = vm::reservation_lock(raddr, 128); 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; *reinterpret_cast<atomic_t<u32>*>(&data) += 0;
@ -1367,17 +1369,17 @@ bool spu_thread::process_mfc_cmd()
if (rdata == data) if (rdata == data)
{ {
mov_rdata(data.data(), to_write.data()); mov_rdata(data.data(), to_write.data());
res++; res.release(old_time + 2);
result = 1; result = 1;
} }
else else
{ {
res &= ~1ull; res.release(old_time);
} }
} }
else else
{ {
res &= ~1ull; res.release(old_time);
} }
} }
} }

View file

@ -276,8 +276,8 @@ struct spu_channel_4_t
public: public:
void clear() void clear()
{ {
values.store({}); values.release({});
value3 = 0; value3.release(0);
} }
// push unconditionally (overwriting latest value), returns true if needs signaling // push unconditionally (overwriting latest value), returns true if needs signaling
@ -364,8 +364,8 @@ struct spu_int_ctrl_t
void clear() void clear()
{ {
mask = 0; mask.release(0);
stat = 0; stat.release(0);
tag = nullptr; tag = nullptr;
} }
}; };

View file

@ -266,7 +266,7 @@ error_code _sys_lwcond_queue_wait(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id
return cpu; return cpu;
} }
mutex->signaled = 1; mutex->signaled.release(1);
return nullptr; return nullptr;
}); });

View file

@ -175,7 +175,7 @@ error_code _sys_lwmutex_unlock(ppu_thread& ppu, u32 lwmutex_id)
return cpu; return cpu;
} }
mutex.signaled = 1; mutex.signaled.release(1);
return nullptr; return nullptr;
}); });