Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

liblv2 HLE: Fix sys_lwcond_signal mode 3 #7934

Merged
merged 1 commit into from Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions rpcs3/Emu/Cell/Modules/sys_lwcond_.cpp
Expand Up @@ -100,7 +100,11 @@ error_code sys_lwcond_signal(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond)
}

// if locking succeeded
lwmutex->all_info++;
lwmutex->lock_var.atomic_op([](typename sys_lwmutex_t::sync_var_t& var)
{
var.waiter++;
var.owner = lwmutex_reserved;
});

// call the syscall
if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, -1, 3))
Expand All @@ -110,7 +114,11 @@ error_code sys_lwcond_signal(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond)
return 0;
}

lwmutex->all_info--;
lwmutex->lock_var.atomic_op([&](typename sys_lwmutex_t::sync_var_t& var)
{
var.waiter--;
var.owner = ppu.id;
});

// unlock the lightweight mutex
sys_lwmutex_unlock(ppu, lwmutex);
Expand Down Expand Up @@ -245,7 +253,11 @@ error_code sys_lwcond_signal_to(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond, u
}

// if locking succeeded
lwmutex->all_info++;
lwmutex->lock_var.atomic_op([](typename sys_lwmutex_t::sync_var_t& var)
{
var.waiter++;
var.owner = lwmutex_reserved;
});

// call the syscall
if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, ppu_thread_id, 3))
Expand All @@ -255,7 +267,11 @@ error_code sys_lwcond_signal_to(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond, u
return 0;
}

lwmutex->all_info--;
lwmutex->lock_var.atomic_op([&](typename sys_lwmutex_t::sync_var_t& var)
{
var.waiter--;
var.owner = ppu.id;
});

// unlock the lightweight mutex
sys_lwmutex_unlock(ppu, lwmutex);
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/Modules/sys_lwmutex_.cpp
Expand Up @@ -178,7 +178,7 @@ error_code sys_lwmutex_lock(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex, u64
// locking succeeded
auto old = lwmutex->vars.owner.exchange(tid);

if (old != lwmutex_reserved && old >> 24 != 1)
if (old != lwmutex_reserved)
{
fmt::throw_exception("Locking failed (lwmutex=*0x%x, owner=0x%x)" HERE, lwmutex, old);
}
Expand Down Expand Up @@ -308,7 +308,7 @@ error_code sys_lwmutex_trylock(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex)
// locking succeeded
auto old = lwmutex->vars.owner.exchange(tid);

if (old != lwmutex_reserved && old >> 24 != 1)
if (old != lwmutex_reserved)
{
fmt::throw_exception("Locking failed (lwmutex=*0x%x, owner=0x%x)" HERE, lwmutex, old);
}
Expand Down