1
0
Fork 0
forked from suyu/suyu

kernel: Ensure all uses of disable_count are balanced

This commit is contained in:
Liam 2022-07-11 10:13:13 -04:00
parent 77137583cd
commit a9a83fa726
3 changed files with 21 additions and 10 deletions

View file

@ -63,14 +63,8 @@ void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduli
auto* scheduler{kernel.CurrentScheduler()};
if (!scheduler || kernel.IsPhantomModeForSingleCore()) {
// HACK: we cannot schedule from this thread, it is not a core thread
RescheduleCores(kernel, cores_needing_scheduling);
if (GetCurrentThread(kernel).GetDisableDispatchCount() == 1) {
// Special case to ensure dummy threads that are waiting block
GetCurrentThread(kernel).IfDummyThreadTryWait();
}
GetCurrentThread(kernel).EnableDispatch();
ASSERT(GetCurrentThread(kernel).GetState() != ThreadState::Waiting);
KScheduler::RescheduleCores(kernel, cores_needing_scheduling);
KScheduler::RescheduleCurrentHLEThread(kernel);
return;
}
@ -83,6 +77,17 @@ void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduli
}
}
void KScheduler::RescheduleCurrentHLEThread(KernelCore& kernel) {
// HACK: we cannot schedule from this thread, it is not a core thread
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() == 1);
// Special case to ensure dummy threads that are waiting block
GetCurrentThread(kernel).IfDummyThreadTryWait();
ASSERT(GetCurrentThread(kernel).GetState() != ThreadState::Waiting);
GetCurrentThread(kernel).EnableDispatch();
}
u64 KScheduler::UpdateHighestPriorityThreads(KernelCore& kernel) {
if (IsSchedulerUpdateNeeded(kernel)) {
return UpdateHighestPriorityThreadsImpl(kernel);

View file

@ -119,6 +119,8 @@ private:
}
static u64 UpdateHighestPriorityThreadsImpl(KernelCore& kernel);
static void RescheduleCurrentHLEThread(KernelCore& kernel);
// Instanced private API.
void ScheduleImpl();
void ScheduleImplFiber();

View file

@ -1106,6 +1106,8 @@ void KThread::IfDummyThreadTryWait() {
return;
}
ASSERT(!kernel.IsPhantomModeForSingleCore());
// Block until we are no longer waiting.
std::unique_lock lk(dummy_wait_lock);
dummy_wait_cv.wait(
@ -1211,10 +1213,12 @@ KScopedDisableDispatch::~KScopedDisableDispatch() {
}
if (GetCurrentThread(kernel).GetDisableDispatchCount() <= 1) {
auto scheduler = kernel.CurrentScheduler();
auto* scheduler = kernel.CurrentScheduler();
if (scheduler) {
if (scheduler && !kernel.IsPhantomModeForSingleCore()) {
scheduler->RescheduleCurrentCore();
} else {
KScheduler::RescheduleCurrentHLEThread(kernel);
}
} else {
GetCurrentThread(kernel).EnableDispatch();