Fix vm::reservation_update

This commit is contained in:
Eladash 2020-08-15 07:56:34 +03:00 committed by Ivan
parent acee590733
commit ee953f7953
2 changed files with 29 additions and 2 deletions

View File

@ -79,6 +79,28 @@ namespace vm
// Memory pages
std::array<memory_page, 0x100000000 / 4096> g_pages{};
void reservation_update(u32 addr, u32 size, bool lsb)
{
u64 old = UINT64_MAX;
const auto cpu = get_current_cpu_thread();
while (true)
{
const auto [ok, rtime] = try_reservation_update(addr, size, lsb);
if (ok || old / 128 < rtime / 128)
{
return;
}
old = rtime;
if (cpu && cpu->test_stopped())
{
return;
}
}
}
static void _register_lock(cpu_thread* _cpu)
{
for (u32 i = 0, max = g_cfg.core.ppu_threads;;)

View File

@ -14,12 +14,17 @@ namespace vm
}
// Update reservation status
inline void reservation_update(u32 addr, u32 size, bool lsb = false)
inline std::pair<bool, u64> try_reservation_update(u32 addr, u32 size, bool lsb = false)
{
// Update reservation info with new timestamp
reservation_acquire(addr, size) += 128;
auto& res = reservation_acquire(addr, size);
const u64 rtime = res;
return {!(rtime & 127) && res.compare_and_swap_test(rtime, rtime + 128), rtime};
}
void reservation_update(u32 addr, u32 size, bool lsb = false);
// Get reservation sync variable
inline atomic_t<u64>& reservation_notifier(u32 addr, u32 size)
{