summaryrefslogtreecommitdiff
path: root/src/core/cpu_manager.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-02-27 19:12:41 -0400
committerGravatar Fernando Sahmkow2020-06-27 11:35:20 -0400
commit04e0f8776c26930d7dc8015e53914b11bf1929c1 (patch)
tree4a8288d6bf8655a2ec0595fdc6d41a3037c5fcad /src/core/cpu_manager.cpp
parentSVC: Correct races on physical core switching. (diff)
downloadyuzu-04e0f8776c26930d7dc8015e53914b11bf1929c1.tar.gz
yuzu-04e0f8776c26930d7dc8015e53914b11bf1929c1.tar.xz
yuzu-04e0f8776c26930d7dc8015e53914b11bf1929c1.zip
General: Add better safety for JIT use.
Diffstat (limited to 'src/core/cpu_manager.cpp')
-rw-r--r--src/core/cpu_manager.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
index 904aacd97..9a261968a 100644
--- a/src/core/cpu_manager.cpp
+++ b/src/core/cpu_manager.cpp
@@ -46,6 +46,11 @@ void CpuManager::GuestThreadFunction(void* cpu_manager_) {
46 cpu_manager->RunGuestThread(); 46 cpu_manager->RunGuestThread();
47} 47}
48 48
49void CpuManager::GuestRewindFunction(void* cpu_manager_) {
50 CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_);
51 cpu_manager->RunGuestLoop();
52}
53
49void CpuManager::IdleThreadFunction(void* cpu_manager_) { 54void CpuManager::IdleThreadFunction(void* cpu_manager_) {
50 CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_); 55 CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_);
51 cpu_manager->RunIdleThread(); 56 cpu_manager->RunIdleThread();
@@ -78,14 +83,22 @@ void CpuManager::RunGuestThread() {
78 auto& sched = kernel.CurrentScheduler(); 83 auto& sched = kernel.CurrentScheduler();
79 sched.OnThreadStart(); 84 sched.OnThreadStart();
80 } 85 }
86 RunGuestLoop();
87}
88
89void CpuManager::RunGuestLoop() {
90 auto& kernel = system.Kernel();
91 auto* thread = kernel.CurrentScheduler().GetCurrentThread();
92 auto host_context = thread->GetHostContext();
93 host_context->SetRewindPoint(std::function<void(void*)>(GuestRewindFunction), this);
94 host_context.reset();
81 while (true) { 95 while (true) {
82 auto* physical_core = &kernel.CurrentPhysicalCore(); 96 auto& physical_core = kernel.CurrentPhysicalCore();
83 while (!physical_core->IsInterrupted()) { 97 while (!physical_core.IsInterrupted()) {
84 physical_core->Run(); 98 physical_core.Run();
85 physical_core = &kernel.CurrentPhysicalCore();
86 } 99 }
87 physical_core->ClearExclusive(); 100 physical_core.ClearExclusive();
88 auto& scheduler = physical_core->Scheduler(); 101 auto& scheduler = physical_core.Scheduler();
89 scheduler.TryDoContextSwitch(); 102 scheduler.TryDoContextSwitch();
90 } 103 }
91} 104}