mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
kern: unconditionally set thread state when appropriate
This commit is contained in:
parent
3356eddcba
commit
ec1d9c4c49
3 changed files with 15 additions and 32 deletions
|
@ -35,11 +35,7 @@ namespace ams::kern {
|
|||
owner_thread->AddWaiter(cur_thread);
|
||||
|
||||
/* Set thread states. */
|
||||
if (AMS_LIKELY(cur_thread->GetState() == KThread::ThreadState_Runnable)) {
|
||||
cur_thread->SetState(KThread::ThreadState_Waiting);
|
||||
} else {
|
||||
KScheduler::SetSchedulerUpdateNeeded();
|
||||
}
|
||||
|
||||
if (owner_thread->IsSuspended()) {
|
||||
owner_thread->ContinueIfHasKernelWaiters();
|
||||
|
@ -49,10 +45,9 @@ namespace ams::kern {
|
|||
/* We're no longer waiting on the lock owner. */
|
||||
{
|
||||
KScopedSchedulerLock sl;
|
||||
KThread *owner_thread = cur_thread->GetLockOwner();
|
||||
if (AMS_UNLIKELY(owner_thread)) {
|
||||
|
||||
if (KThread *owner_thread = cur_thread->GetLockOwner(); AMS_UNLIKELY(owner_thread != nullptr)) {
|
||||
owner_thread->RemoveWaiter(cur_thread);
|
||||
KScheduler::SetSchedulerUpdateNeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,17 +65,13 @@ namespace ams::kern {
|
|||
|
||||
/* Pass the lock to the next owner. */
|
||||
uintptr_t next_tag = 0;
|
||||
if (next_owner) {
|
||||
if (next_owner != nullptr) {
|
||||
next_tag = reinterpret_cast<uintptr_t>(next_owner);
|
||||
if (num_waiters > 1) {
|
||||
next_tag |= 0x1;
|
||||
}
|
||||
|
||||
if (AMS_LIKELY(next_owner->GetState() == KThread::ThreadState_Waiting)) {
|
||||
next_owner->SetState(KThread::ThreadState_Runnable);
|
||||
} else {
|
||||
KScheduler::SetSchedulerUpdateNeeded();
|
||||
}
|
||||
|
||||
if (next_owner->IsSuspended()) {
|
||||
next_owner->ContinueIfHasKernelWaiters();
|
||||
|
|
|
@ -740,25 +740,22 @@ namespace ams::kern {
|
|||
/* If we have no exception thread, we succeeded. */
|
||||
if (m_exception_thread == nullptr) {
|
||||
m_exception_thread = cur_thread;
|
||||
KScheduler::SetSchedulerUpdateNeeded();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Otherwise, wait for us to not have an exception thread. */
|
||||
cur_thread->SetAddressKey(address_key | 1);
|
||||
m_exception_thread->AddWaiter(cur_thread);
|
||||
if (cur_thread->GetState() == KThread::ThreadState_Runnable) {
|
||||
cur_thread->SetState(KThread::ThreadState_Waiting);
|
||||
} else {
|
||||
KScheduler::SetSchedulerUpdateNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove the thread as a waiter from the lock owner. */
|
||||
{
|
||||
KScopedSchedulerLock sl;
|
||||
KThread *owner_thread = cur_thread->GetLockOwner();
|
||||
if (owner_thread != nullptr) {
|
||||
|
||||
if (KThread *owner_thread = cur_thread->GetLockOwner(); owner_thread != nullptr) {
|
||||
owner_thread->RemoveWaiter(cur_thread);
|
||||
KScheduler::SetSchedulerUpdateNeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -779,14 +776,11 @@ namespace ams::kern {
|
|||
|
||||
/* Remove waiter thread. */
|
||||
s32 num_waiters;
|
||||
KThread *next = thread->RemoveWaiterByKey(std::addressof(num_waiters), reinterpret_cast<uintptr_t>(std::addressof(m_exception_thread)));
|
||||
if (next != nullptr) {
|
||||
if (next->GetState() == KThread::ThreadState_Waiting) {
|
||||
if (KThread *next = thread->RemoveWaiterByKey(std::addressof(num_waiters), reinterpret_cast<uintptr_t>(std::addressof(m_exception_thread))); next != nullptr) {
|
||||
next->SetState(KThread::ThreadState_Runnable);
|
||||
} else {
|
||||
}
|
||||
|
||||
KScheduler::SetSchedulerUpdateNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -218,11 +218,9 @@ namespace ams::kern {
|
|||
KThread *task_thread = Kernel::GetInterruptTaskManager().GetThread();
|
||||
{
|
||||
KScopedSchedulerLock sl;
|
||||
if (AMS_LIKELY(task_thread->GetState() == KThread::ThreadState_Waiting)) {
|
||||
task_thread->SetState(KThread::ThreadState_Runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KScheduler::SwitchThread(KThread *next_thread) {
|
||||
KProcess *cur_process = GetCurrentProcessPointer();
|
||||
|
|
Loading…
Reference in a new issue