summaryrefslogtreecommitdiff
path: root/src/core/cpu_manager.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-01-26 14:07:22 -0400
committerGravatar Fernando Sahmkow2020-01-26 14:07:22 -0400
commite4a1ead897575ee9222b4fc1021aaa9cc58f12c8 (patch)
treeef544a51ba2480400df62d40706f68fa3ae62693 /src/core/cpu_manager.cpp
parentArmInterface: Delegate Exclusive monitor factory to exclusive monitor interfa... (diff)
downloadyuzu-e4a1ead897575ee9222b4fc1021aaa9cc58f12c8.tar.gz
yuzu-e4a1ead897575ee9222b4fc1021aaa9cc58f12c8.tar.xz
yuzu-e4a1ead897575ee9222b4fc1021aaa9cc58f12c8.zip
Core: Refactor CpuCoreManager to CpuManager and Cpu to Core Manager.
This commit instends on better naming the new purpose of this classes.
Diffstat (limited to 'src/core/cpu_manager.cpp')
-rw-r--r--src/core/cpu_manager.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
new file mode 100644
index 000000000..abc8aad9e
--- /dev/null
+++ b/src/core/cpu_manager.cpp
@@ -0,0 +1,84 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "common/assert.h"
6#include "core/arm/exclusive_monitor.h"
7#include "core/core.h"
8#include "core/core_manager.h"
9#include "core/core_timing.h"
10#include "core/cpu_manager.h"
11#include "core/gdbstub/gdbstub.h"
12#include "core/settings.h"
13
14namespace Core {
15
16CpuManager::CpuManager(System& system) : system{system} {}
17CpuManager::~CpuManager() = default;
18
19void CpuManager::Initialize() {
20
21 for (std::size_t index = 0; index < core_managers.size(); ++index) {
22 core_managers[index] = std::make_unique<CoreManager>(system, index);
23 }
24}
25
26void CpuManager::Shutdown() {
27 for (auto& cpu_core : core_managers) {
28 cpu_core.reset();
29 }
30}
31
32CoreManager& CpuManager::GetCoreManager(std::size_t index) {
33 return *core_managers.at(index);
34}
35
36const CoreManager& CpuManager::GetCoreManager(std::size_t index) const {
37 return *core_managers.at(index);
38}
39
40CoreManager& CpuManager::GetCurrentCoreManager() {
41 // Otherwise, use single-threaded mode active_core variable
42 return *core_managers[active_core];
43}
44
45const CoreManager& CpuManager::GetCurrentCoreManager() const {
46 // Otherwise, use single-threaded mode active_core variable
47 return *core_managers[active_core];
48}
49
50void CpuManager::RunLoop(bool tight_loop) {
51 if (GDBStub::IsServerEnabled()) {
52 GDBStub::HandlePacket();
53
54 // If the loop is halted and we want to step, use a tiny (1) number of instructions to
55 // execute. Otherwise, get out of the loop function.
56 if (GDBStub::GetCpuHaltFlag()) {
57 if (GDBStub::GetCpuStepFlag()) {
58 tight_loop = false;
59 } else {
60 return;
61 }
62 }
63 }
64
65 auto& core_timing = system.CoreTiming();
66 core_timing.ResetRun();
67 bool keep_running{};
68 do {
69 keep_running = false;
70 for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
71 core_timing.SwitchContext(active_core);
72 if (core_timing.CanCurrentContextRun()) {
73 core_managers[active_core]->RunLoop(tight_loop);
74 }
75 keep_running |= core_timing.CanCurrentContextRun();
76 }
77 } while (keep_running);
78
79 if (GDBStub::IsServerEnabled()) {
80 GDBStub::SetCpuStepFlag(false);
81 }
82}
83
84} // namespace Core