summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/scheduler.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-03-06 20:20:36 -0400
committerGravatar Fernando Sahmkow2020-06-27 11:35:31 -0400
commit3de33348e41ab824eb13f202eccc29d5be2a6d42 (patch)
tree1ba88c8268decee6116289f58944712c26073941 /src/core/hle/kernel/scheduler.cpp
parentScheduler: Correct assert. (diff)
downloadyuzu-3de33348e41ab824eb13f202eccc29d5be2a6d42.tar.gz
yuzu-3de33348e41ab824eb13f202eccc29d5be2a6d42.tar.xz
yuzu-3de33348e41ab824eb13f202eccc29d5be2a6d42.zip
Scheduler: Protect on closed threads.
Diffstat (limited to 'src/core/hle/kernel/scheduler.cpp')
-rw-r--r--src/core/hle/kernel/scheduler.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index 4e2a5adf3..74d3731fc 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -604,7 +604,6 @@ void Scheduler::SwitchContextStep2() {
604 604
605 if (new_thread) { 605 if (new_thread) {
606 auto& cpu_core = system.ArmInterface(core_id); 606 auto& cpu_core = system.ArmInterface(core_id);
607 new_thread->context_guard.lock();
608 cpu_core.Lock(); 607 cpu_core.Lock();
609 ASSERT_MSG(new_thread->GetSchedulingStatus() == ThreadSchedStatus::Runnable, 608 ASSERT_MSG(new_thread->GetSchedulingStatus() == ThreadSchedStatus::Runnable,
610 "Thread must be runnable."); 609 "Thread must be runnable.");
@@ -685,13 +684,24 @@ void Scheduler::OnSwitch(void* this_scheduler) {
685 684
686void Scheduler::SwitchToCurrent() { 685void Scheduler::SwitchToCurrent() {
687 while (true) { 686 while (true) {
688 std::shared_ptr<Common::Fiber> next_context; 687 guard.lock();
689 if (current_thread != nullptr) { 688 selected_thread = selected_thread_set;
690 next_context = current_thread->GetHostContext(); 689 current_thread = selected_thread;
691 } else { 690 guard.unlock();
692 next_context = idle_thread->GetHostContext(); 691 while (!is_context_switch_pending) {
692 current_thread->context_guard.lock();
693 if (current_thread->GetSchedulingStatus() != ThreadSchedStatus::Runnable) {
694 current_thread->context_guard.unlock();
695 break;
696 }
697 std::shared_ptr<Common::Fiber> next_context;
698 if (current_thread != nullptr) {
699 next_context = current_thread->GetHostContext();
700 } else {
701 next_context = idle_thread->GetHostContext();
702 }
703 Common::Fiber::YieldTo(switch_fiber, next_context);
693 } 704 }
694 Common::Fiber::YieldTo(switch_fiber, next_context);
695 } 705 }
696} 706}
697 707