summaryrefslogtreecommitdiff
path: root/src/core
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
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')
-rw-r--r--src/core/cpu_manager.cpp11
-rw-r--r--src/core/cpu_manager.h2
-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
7 files changed, 29 insertions, 31 deletions
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
index c35438c6f..8f04fb8f5 100644
--- a/src/core/cpu_manager.cpp
+++ b/src/core/cpu_manager.cpp
@@ -111,7 +111,7 @@ void CpuManager::MultiCoreRunGuestThread() {
111 auto& kernel = system.Kernel(); 111 auto& kernel = system.Kernel();
112 kernel.CurrentScheduler()->OnThreadStart(); 112 kernel.CurrentScheduler()->OnThreadStart();
113 auto* thread = kernel.CurrentScheduler()->GetCurrentThread(); 113 auto* thread = kernel.CurrentScheduler()->GetCurrentThread();
114 auto host_context = thread->GetHostContext(); 114 auto& host_context = thread->GetHostContext();
115 host_context->SetRewindPoint(GuestRewindFunction, this); 115 host_context->SetRewindPoint(GuestRewindFunction, this);
116 MultiCoreRunGuestLoop(); 116 MultiCoreRunGuestLoop();
117} 117}
@@ -148,8 +148,7 @@ void CpuManager::MultiCoreRunSuspendThread() {
148 auto core = kernel.GetCurrentHostThreadID(); 148 auto core = kernel.GetCurrentHostThreadID();
149 auto& scheduler = *kernel.CurrentScheduler(); 149 auto& scheduler = *kernel.CurrentScheduler();
150 Kernel::KThread* current_thread = scheduler.GetCurrentThread(); 150 Kernel::KThread* current_thread = scheduler.GetCurrentThread();
151 Common::Fiber::YieldTo(current_thread->GetHostContext(), 151 Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[core].host_context);
152 core_data[core].host_context.get());
153 ASSERT(scheduler.ContextSwitchPending()); 152 ASSERT(scheduler.ContextSwitchPending());
154 ASSERT(core == kernel.GetCurrentHostThreadID()); 153 ASSERT(core == kernel.GetCurrentHostThreadID());
155 scheduler.RescheduleCurrentCore(); 154 scheduler.RescheduleCurrentCore();
@@ -202,7 +201,7 @@ void CpuManager::SingleCoreRunGuestThread() {
202 auto& kernel = system.Kernel(); 201 auto& kernel = system.Kernel();
203 kernel.CurrentScheduler()->OnThreadStart(); 202 kernel.CurrentScheduler()->OnThreadStart();
204 auto* thread = kernel.CurrentScheduler()->GetCurrentThread(); 203 auto* thread = kernel.CurrentScheduler()->GetCurrentThread();
205 auto host_context = thread->GetHostContext(); 204 auto& host_context = thread->GetHostContext();
206 host_context->SetRewindPoint(GuestRewindFunction, this); 205 host_context->SetRewindPoint(GuestRewindFunction, this);
207 SingleCoreRunGuestLoop(); 206 SingleCoreRunGuestLoop();
208} 207}
@@ -246,7 +245,7 @@ void CpuManager::SingleCoreRunSuspendThread() {
246 auto core = kernel.GetCurrentHostThreadID(); 245 auto core = kernel.GetCurrentHostThreadID();
247 auto& scheduler = *kernel.CurrentScheduler(); 246 auto& scheduler = *kernel.CurrentScheduler();
248 Kernel::KThread* current_thread = scheduler.GetCurrentThread(); 247 Kernel::KThread* current_thread = scheduler.GetCurrentThread();
249 Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[0].host_context.get()); 248 Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[0].host_context);
250 ASSERT(scheduler.ContextSwitchPending()); 249 ASSERT(scheduler.ContextSwitchPending());
251 ASSERT(core == kernel.GetCurrentHostThreadID()); 250 ASSERT(core == kernel.GetCurrentHostThreadID());
252 scheduler.RescheduleCurrentCore(); 251 scheduler.RescheduleCurrentCore();
@@ -364,7 +363,7 @@ void CpuManager::RunThread(std::size_t core) {
364 363
365 auto current_thread = system.Kernel().CurrentScheduler()->GetCurrentThread(); 364 auto current_thread = system.Kernel().CurrentScheduler()->GetCurrentThread();
366 data.is_running = true; 365 data.is_running = true;
367 Common::Fiber::YieldTo(data.host_context.get(), current_thread->GetHostContext()); 366 Common::Fiber::YieldTo(data.host_context, current_thread->GetHostContext());
368 data.is_running = false; 367 data.is_running = false;
369 data.is_paused = true; 368 data.is_paused = true;
370 data.exit_barrier->Wait(); 369 data.exit_barrier->Wait();
diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.h
index 5ea149f1f..17420c941 100644
--- a/src/core/cpu_manager.h
+++ b/src/core/cpu_manager.h
@@ -83,7 +83,7 @@ private:
83 void RunThread(std::size_t core); 83 void RunThread(std::size_t core);
84 84
85 struct CoreData { 85 struct CoreData {
86 std::unique_ptr<Common::Fiber> host_context; 86 std::shared_ptr<Common::Fiber> host_context;
87 std::unique_ptr<Common::Event> enter_barrier; 87 std::unique_ptr<Common::Event> enter_barrier;
88 std::unique_ptr<Common::Event> exit_barrier; 88 std::unique_ptr<Common::Event> exit_barrier;
89 std::atomic<bool> is_running; 89 std::atomic<bool> is_running;
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();