mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-18 01:46:47 +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);
|
owner_thread->AddWaiter(cur_thread);
|
||||||
|
|
||||||
/* Set thread states. */
|
/* Set thread states. */
|
||||||
if (AMS_LIKELY(cur_thread->GetState() == KThread::ThreadState_Runnable)) {
|
|
||||||
cur_thread->SetState(KThread::ThreadState_Waiting);
|
cur_thread->SetState(KThread::ThreadState_Waiting);
|
||||||
} else {
|
|
||||||
KScheduler::SetSchedulerUpdateNeeded();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (owner_thread->IsSuspended()) {
|
if (owner_thread->IsSuspended()) {
|
||||||
owner_thread->ContinueIfHasKernelWaiters();
|
owner_thread->ContinueIfHasKernelWaiters();
|
||||||
|
@ -49,10 +45,9 @@ namespace ams::kern {
|
||||||
/* We're no longer waiting on the lock owner. */
|
/* We're no longer waiting on the lock owner. */
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl;
|
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);
|
owner_thread->RemoveWaiter(cur_thread);
|
||||||
KScheduler::SetSchedulerUpdateNeeded();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,17 +65,13 @@ namespace ams::kern {
|
||||||
|
|
||||||
/* Pass the lock to the next owner. */
|
/* Pass the lock to the next owner. */
|
||||||
uintptr_t next_tag = 0;
|
uintptr_t next_tag = 0;
|
||||||
if (next_owner) {
|
if (next_owner != nullptr) {
|
||||||
next_tag = reinterpret_cast<uintptr_t>(next_owner);
|
next_tag = reinterpret_cast<uintptr_t>(next_owner);
|
||||||
if (num_waiters > 1) {
|
if (num_waiters > 1) {
|
||||||
next_tag |= 0x1;
|
next_tag |= 0x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AMS_LIKELY(next_owner->GetState() == KThread::ThreadState_Waiting)) {
|
|
||||||
next_owner->SetState(KThread::ThreadState_Runnable);
|
next_owner->SetState(KThread::ThreadState_Runnable);
|
||||||
} else {
|
|
||||||
KScheduler::SetSchedulerUpdateNeeded();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next_owner->IsSuspended()) {
|
if (next_owner->IsSuspended()) {
|
||||||
next_owner->ContinueIfHasKernelWaiters();
|
next_owner->ContinueIfHasKernelWaiters();
|
||||||
|
|
|
@ -740,25 +740,22 @@ namespace ams::kern {
|
||||||
/* If we have no exception thread, we succeeded. */
|
/* If we have no exception thread, we succeeded. */
|
||||||
if (m_exception_thread == nullptr) {
|
if (m_exception_thread == nullptr) {
|
||||||
m_exception_thread = cur_thread;
|
m_exception_thread = cur_thread;
|
||||||
|
KScheduler::SetSchedulerUpdateNeeded();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Otherwise, wait for us to not have an exception thread. */
|
/* Otherwise, wait for us to not have an exception thread. */
|
||||||
cur_thread->SetAddressKey(address_key | 1);
|
cur_thread->SetAddressKey(address_key | 1);
|
||||||
m_exception_thread->AddWaiter(cur_thread);
|
m_exception_thread->AddWaiter(cur_thread);
|
||||||
if (cur_thread->GetState() == KThread::ThreadState_Runnable) {
|
|
||||||
cur_thread->SetState(KThread::ThreadState_Waiting);
|
cur_thread->SetState(KThread::ThreadState_Waiting);
|
||||||
} else {
|
|
||||||
KScheduler::SetSchedulerUpdateNeeded();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove the thread as a waiter from the lock owner. */
|
/* Remove the thread as a waiter from the lock owner. */
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl;
|
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);
|
owner_thread->RemoveWaiter(cur_thread);
|
||||||
KScheduler::SetSchedulerUpdateNeeded();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -779,14 +776,11 @@ namespace ams::kern {
|
||||||
|
|
||||||
/* Remove waiter thread. */
|
/* Remove waiter thread. */
|
||||||
s32 num_waiters;
|
s32 num_waiters;
|
||||||
KThread *next = thread->RemoveWaiterByKey(std::addressof(num_waiters), reinterpret_cast<uintptr_t>(std::addressof(m_exception_thread)));
|
if (KThread *next = thread->RemoveWaiterByKey(std::addressof(num_waiters), reinterpret_cast<uintptr_t>(std::addressof(m_exception_thread))); next != nullptr) {
|
||||||
if (next != nullptr) {
|
|
||||||
if (next->GetState() == KThread::ThreadState_Waiting) {
|
|
||||||
next->SetState(KThread::ThreadState_Runnable);
|
next->SetState(KThread::ThreadState_Runnable);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
KScheduler::SetSchedulerUpdateNeeded();
|
KScheduler::SetSchedulerUpdateNeeded();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -218,11 +218,9 @@ namespace ams::kern {
|
||||||
KThread *task_thread = Kernel::GetInterruptTaskManager().GetThread();
|
KThread *task_thread = Kernel::GetInterruptTaskManager().GetThread();
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl;
|
KScopedSchedulerLock sl;
|
||||||
if (AMS_LIKELY(task_thread->GetState() == KThread::ThreadState_Waiting)) {
|
|
||||||
task_thread->SetState(KThread::ThreadState_Runnable);
|
task_thread->SetState(KThread::ThreadState_Runnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void KScheduler::SwitchThread(KThread *next_thread) {
|
void KScheduler::SwitchThread(KThread *next_thread) {
|
||||||
KProcess *cur_process = GetCurrentProcessPointer();
|
KProcess *cur_process = GetCurrentProcessPointer();
|
||||||
|
|
Loading…
Reference in a new issue