summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar bunnei2021-03-05 17:08:48 -0800
committerGravatar GitHub2021-03-05 17:08:48 -0800
commit7b29a8ce4e1f94bec7e7828fb1674e1b43b937c5 (patch)
tree503cbe4fb52939512f8ee0c976e46e9293de3c4c /src/core/hle/kernel
parentMerge pull request #6034 from Morph1984/mbedtls (diff)
parentRevert "core: Switch to unique_ptr for usage of Common::Fiber." (diff)
downloadyuzu-7b29a8ce4e1f94bec7e7828fb1674e1b43b937c5.tar.gz
yuzu-7b29a8ce4e1f94bec7e7828fb1674e1b43b937c5.tar.xz
yuzu-7b29a8ce4e1f94bec7e7828fb1674e1b43b937c5.zip
Merge pull request #6039 from yuzu-emu/revert-6006-fiber-unique-ptr
Revert "core: Switch to unique_ptr for usage of Common::Fiber."
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/k_scheduler.cpp18
-rw-r--r--src/core/hle/kernel/k_scheduler.h10
-rw-r--r--src/core/hle/kernel/k_thread.cpp6
-rw-r--r--src/core/hle/kernel/k_thread.h10
-rw-r--r--src/core/hle/kernel/svc.cpp3
5 files changed, 23 insertions, 24 deletions
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp
index 465036f3d..bb5f43b53 100644
--- a/src/core/hle/kernel/k_scheduler.cpp
+++ b/src/core/hle/kernel/k_scheduler.cpp
@@ -608,7 +608,7 @@ void KScheduler::YieldToAnyThread(KernelCore& kernel) {
608} 608}
609 609
610KScheduler::KScheduler(Core::System& system, s32 core_id) : system(system), core_id(core_id) { 610KScheduler::KScheduler(Core::System& system, s32 core_id) : system(system), core_id(core_id) {
611 switch_fiber = std::make_unique<Common::Fiber>(OnSwitch, this); 611 switch_fiber = std::make_shared<Common::Fiber>(OnSwitch, this);
612 state.needs_scheduling.store(true); 612 state.needs_scheduling.store(true);
613 state.interrupt_task_thread_runnable = false; 613 state.interrupt_task_thread_runnable = false;
614 state.should_count_idle = false; 614 state.should_count_idle = false;
@@ -726,15 +726,15 @@ void KScheduler::ScheduleImpl() {
726 // Save context for previous thread 726 // Save context for previous thread
727 Unload(previous_thread); 727 Unload(previous_thread);
728 728
729 Common::Fiber* old_context; 729 std::shared_ptr<Common::Fiber>* old_context;
730 if (previous_thread != nullptr) { 730 if (previous_thread != nullptr) {
731 old_context = previous_thread->GetHostContext(); 731 old_context = &previous_thread->GetHostContext();
732 } else { 732 } else {
733 old_context = idle_thread->GetHostContext(); 733 old_context = &idle_thread->GetHostContext();
734 } 734 }
735 guard.unlock(); 735 guard.unlock();
736 736
737 Common::Fiber::YieldTo(old_context, switch_fiber.get()); 737 Common::Fiber::YieldTo(*old_context, switch_fiber);
738 /// When a thread wakes up, the scheduler may have changed to other in another core. 738 /// When a thread wakes up, the scheduler may have changed to other in another core.
739 auto& next_scheduler = *system.Kernel().CurrentScheduler(); 739 auto& next_scheduler = *system.Kernel().CurrentScheduler();
740 next_scheduler.SwitchContextStep2(); 740 next_scheduler.SwitchContextStep2();
@@ -769,13 +769,13 @@ void KScheduler::SwitchToCurrent() {
769 break; 769 break;
770 } 770 }
771 } 771 }
772 Common::Fiber* next_context; 772 std::shared_ptr<Common::Fiber>* next_context;
773 if (next_thread != nullptr) { 773 if (next_thread != nullptr) {
774 next_context = next_thread->GetHostContext(); 774 next_context = &next_thread->GetHostContext();
775 } else { 775 } else {
776 next_context = idle_thread->GetHostContext(); 776 next_context = &idle_thread->GetHostContext();
777 } 777 }
778 Common::Fiber::YieldTo(switch_fiber.get(), next_context); 778 Common::Fiber::YieldTo(switch_fiber, *next_context);
779 } while (!is_switch_pending()); 779 } while (!is_switch_pending());
780 } 780 }
781} 781}
diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h
index a4285c595..f595b9a5c 100644
--- a/src/core/hle/kernel/k_scheduler.h
+++ b/src/core/hle/kernel/k_scheduler.h
@@ -68,12 +68,12 @@ public:
68 68
69 void OnThreadStart(); 69 void OnThreadStart();
70 70
71 [[nodiscard]] Common::Fiber* ControlContext() { 71 [[nodiscard]] std::shared_ptr<Common::Fiber>& ControlContext() {
72 return switch_fiber.get(); 72 return switch_fiber;
73 } 73 }
74 74
75 [[nodiscard]] const Common::Fiber* ControlContext() const { 75 [[nodiscard]] const std::shared_ptr<Common::Fiber>& ControlContext() const {
76 return switch_fiber.get(); 76 return switch_fiber;
77 } 77 }
78 78
79 [[nodiscard]] u64 UpdateHighestPriorityThread(KThread* highest_thread); 79 [[nodiscard]] u64 UpdateHighestPriorityThread(KThread* highest_thread);
@@ -178,7 +178,7 @@ private:
178 178
179 KThread* idle_thread; 179 KThread* idle_thread;
180 180
181 std::unique_ptr<Common::Fiber> switch_fiber{}; 181 std::shared_ptr<Common::Fiber> switch_fiber{};
182 182
183 struct SchedulingState { 183 struct SchedulingState {
184 std::atomic<bool> needs_scheduling; 184 std::atomic<bool> needs_scheduling;
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index f49e31b72..1661afbd9 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -991,6 +991,10 @@ void KThread::SetState(ThreadState state) {
991 } 991 }
992} 992}
993 993
994std::shared_ptr<Common::Fiber>& KThread::GetHostContext() {
995 return host_context;
996}
997
994ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, ThreadType type_flags, 998ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, ThreadType type_flags,
995 std::string name, VAddr entry_point, 999 std::string name, VAddr entry_point,
996 u32 priority, u64 arg, s32 processor_id, 1000 u32 priority, u64 arg, s32 processor_id,
@@ -1024,7 +1028,7 @@ ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, Thread
1024 scheduler.AddThread(thread); 1028 scheduler.AddThread(thread);
1025 1029
1026 thread->host_context = 1030 thread->host_context =
1027 std::make_unique<Common::Fiber>(std::move(thread_start_func), thread_start_parameter); 1031 std::make_shared<Common::Fiber>(std::move(thread_start_func), thread_start_parameter);
1028 1032
1029 return MakeResult<std::shared_ptr<KThread>>(std::move(thread)); 1033 return MakeResult<std::shared_ptr<KThread>>(std::move(thread));
1030} 1034}
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h
index a2893d939..c8ac656a4 100644
--- a/src/core/hle/kernel/k_thread.h
+++ b/src/core/hle/kernel/k_thread.h
@@ -293,13 +293,7 @@ public:
293 return thread_context_64; 293 return thread_context_64;
294 } 294 }
295 295
296 [[nodiscard]] Common::Fiber* GetHostContext() { 296 [[nodiscard]] std::shared_ptr<Common::Fiber>& GetHostContext();
297 return host_context.get();
298 }
299
300 [[nodiscard]] const Common::Fiber* GetHostContext() const {
301 return host_context.get();
302 }
303 297
304 [[nodiscard]] ThreadState GetState() const { 298 [[nodiscard]] ThreadState GetState() const {
305 return thread_state & ThreadState::Mask; 299 return thread_state & ThreadState::Mask;
@@ -725,7 +719,7 @@ private:
725 Common::SpinLock context_guard{}; 719 Common::SpinLock context_guard{};
726 720
727 // For emulation 721 // For emulation
728 std::unique_ptr<Common::Fiber> host_context{}; 722 std::shared_ptr<Common::Fiber> host_context{};
729 723
730 // For debugging 724 // For debugging
731 std::vector<KSynchronizationObject*> wait_objects_for_debugging; 725 std::vector<KSynchronizationObject*> wait_objects_for_debugging;
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index d04116115..cc8fa6576 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -2626,7 +2626,8 @@ void Call(Core::System& system, u32 immediate) {
2626 kernel.ExitSVCProfile(); 2626 kernel.ExitSVCProfile();
2627 2627
2628 if (!thread->IsCallingSvc()) { 2628 if (!thread->IsCallingSvc()) {
2629 thread->GetHostContext()->Rewind(); 2629 auto* host_context = thread->GetHostContext().get();
2630 host_context->Rewind();
2630 } 2631 }
2631 2632
2632 system.EnterDynarmicProfile(); 2633 system.EnterDynarmicProfile();