summaryrefslogtreecommitdiff
path: root/src/core/core.h
diff options
context:
space:
mode:
authorGravatar bunnei2018-05-02 21:26:14 -0400
committerGravatar bunnei2018-05-10 19:34:46 -0400
commit9776ff91797423a9cf19571faafe4648fb5a1d1d (patch)
tree46a7c94c53faee26b805f6290a09c45d33f7bf11 /src/core/core.h
parentcore: Move common CPU core things to its own class. (diff)
downloadyuzu-9776ff91797423a9cf19571faafe4648fb5a1d1d.tar.gz
yuzu-9776ff91797423a9cf19571faafe4648fb5a1d1d.tar.xz
yuzu-9776ff91797423a9cf19571faafe4648fb5a1d1d.zip
core: Create a thread for each CPU core, keep in lock-step with a barrier.
Diffstat (limited to 'src/core/core.h')
-rw-r--r--src/core/core.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/core/core.h b/src/core/core.h
index 6e6cc7579..21a0b074b 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -7,6 +7,7 @@
7#include <array> 7#include <array>
8#include <memory> 8#include <memory>
9#include <string> 9#include <string>
10#include <thread>
10#include "common/common_types.h" 11#include "common/common_types.h"
11#include "core/core_cpu.h" 12#include "core/core_cpu.h"
12#include "core/hle/kernel/kernel.h" 13#include "core/hle/kernel/kernel.h"
@@ -112,7 +113,7 @@ public:
112 * @returns A reference to the emulated CPU. 113 * @returns A reference to the emulated CPU.
113 */ 114 */
114 ARM_Interface& CPU() { 115 ARM_Interface& CPU() {
115 return cpu_cores[0]->CPU(); 116 return CurrentCpuCore().CPU();
116 } 117 }
117 118
118 Tegra::GPU& GPU() { 119 Tegra::GPU& GPU() {
@@ -120,7 +121,7 @@ public:
120 } 121 }
121 122
122 Kernel::Scheduler& Scheduler() { 123 Kernel::Scheduler& Scheduler() {
123 return cpu_cores[0]->Scheduler(); 124 return CurrentCpuCore().Scheduler();
124 } 125 }
125 126
126 Kernel::SharedPtr<Kernel::Process>& CurrentProcess() { 127 Kernel::SharedPtr<Kernel::Process>& CurrentProcess() {
@@ -157,6 +158,14 @@ public:
157 } 158 }
158 159
159private: 160private:
161 /// Returns the current CPU core based on the calling host thread
162 Cpu& CurrentCpuCore() {
163 const auto& search = thread_to_cpu.find(std::this_thread::get_id());
164 ASSERT(search != thread_to_cpu.end());
165 ASSERT(search->second);
166 return *search->second;
167 }
168
160 /** 169 /**
161 * Initialize the emulated system. 170 * Initialize the emulated system.
162 * @param emu_window Pointer to the host-system window used for video output and keyboard input. 171 * @param emu_window Pointer to the host-system window used for video output and keyboard input.
@@ -167,14 +176,12 @@ private:
167 176
168 /// AppLoader used to load the current executing application 177 /// AppLoader used to load the current executing application
169 std::unique_ptr<Loader::AppLoader> app_loader; 178 std::unique_ptr<Loader::AppLoader> app_loader;
170
171 std::array<std::unique_ptr<Cpu>, 4> cpu_cores;
172 std::unique_ptr<Tegra::GPU> gpu_core; 179 std::unique_ptr<Tegra::GPU> gpu_core;
173 std::shared_ptr<Tegra::DebugContext> debug_context; 180 std::shared_ptr<Tegra::DebugContext> debug_context;
174 Kernel::SharedPtr<Kernel::Process> current_process; 181 Kernel::SharedPtr<Kernel::Process> current_process;
175 182 std::shared_ptr<CpuBarrier> cpu_barrier;
176 /// When true, signals that a reschedule should happen 183 std::array<std::shared_ptr<Cpu>, NUM_CPU_CORES> cpu_cores;
177 bool reschedule_pending{}; 184 std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads;
178 185
179 /// Service manager 186 /// Service manager
180 std::shared_ptr<Service::SM::ServiceManager> service_manager; 187 std::shared_ptr<Service::SM::ServiceManager> service_manager;
@@ -186,6 +193,9 @@ private:
186 193
187 ResultStatus status = ResultStatus::Success; 194 ResultStatus status = ResultStatus::Success;
188 std::string status_details = ""; 195 std::string status_details = "";
196
197 /// Map of guest threads to CPU cores
198 std::map<std::thread::id, std::shared_ptr<Cpu>> thread_to_cpu;
189}; 199};
190 200
191inline ARM_Interface& CPU() { 201inline ARM_Interface& CPU() {