kern: fix use of plr vs plr_heap, fix close/unlock order in ArbitrateLock

This commit is contained in:
Michael Scire 2021-10-19 01:19:31 -07:00
parent 52c914afcc
commit 42b6c2dd95
4 changed files with 21 additions and 15 deletions

View file

@ -113,6 +113,7 @@ namespace ams::kern {
ThreadQueueImplForKConditionVariableWaitForAddress wait_queue;
/* Wait for the address. */
KThread *owner_thread;
{
KScopedSchedulerLock sl;
@ -127,8 +128,8 @@ namespace ams::kern {
R_SUCCEED_IF(test_tag != (handle | ams::svc::HandleWaitMask));
/* Get the lock owner thread. */
KScopedAutoObject owner_thread = GetCurrentProcess().GetHandleTable().GetObjectWithoutPseudoHandle<KThread>(handle);
R_UNLESS(owner_thread.IsNotNull(), svc::ResultInvalidHandle());
owner_thread = GetCurrentProcess().GetHandleTable().GetObjectWithoutPseudoHandle<KThread>(handle).ReleasePointerUnsafe();
R_UNLESS(owner_thread != nullptr, svc::ResultInvalidHandle());
/* Update the lock. */
cur_thread->SetAddressKey(addr, value);
@ -138,6 +139,9 @@ namespace ams::kern {
cur_thread->BeginWait(std::addressof(wait_queue));
}
/* Close our reference to the owner thread, now that the wait is over. */
owner_thread->Close();
/* Get the wait result. */
return cur_thread->GetWaitResult();
}