summaryrefslogtreecommitdiff
path: root/src/core/core_cpu.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_cpu.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_cpu.h')
-rw-r--r--src/core/core_cpu.h33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h
index 312db1655..e6ed698cc 100644
--- a/src/core/core_cpu.h
+++ b/src/core/core_cpu.h
@@ -4,7 +4,9 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <condition_variable>
7#include <memory> 8#include <memory>
9#include <mutex>
8#include <string> 10#include <string>
9#include "common/common_types.h" 11#include "common/common_types.h"
10 12
@@ -16,9 +18,32 @@ class Scheduler;
16 18
17namespace Core { 19namespace Core {
18 20
21constexpr unsigned NUM_CPU_CORES{4};
22
23class CpuBarrier {
24public:
25 void Rendezvous() {
26 std::unique_lock<std::mutex> lock(mutex);
27
28 --cores_waiting;
29 if (!cores_waiting) {
30 cores_waiting = NUM_CPU_CORES;
31 condition.notify_all();
32 return;
33 }
34
35 condition.wait(lock);
36 }
37
38private:
39 unsigned cores_waiting{NUM_CPU_CORES};
40 std::mutex mutex;
41 std::condition_variable condition;
42};
43
19class Cpu { 44class Cpu {
20public: 45public:
21 Cpu(); 46 Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index);
22 47
23 void RunLoop(bool tight_loop = true); 48 void RunLoop(bool tight_loop = true);
24 49
@@ -34,13 +59,19 @@ public:
34 return *scheduler; 59 return *scheduler;
35 } 60 }
36 61
62 bool IsMainCore() const {
63 return core_index == 0;
64 }
65
37private: 66private:
38 void Reschedule(); 67 void Reschedule();
39 68
40 std::shared_ptr<ARM_Interface> arm_interface; 69 std::shared_ptr<ARM_Interface> arm_interface;
70 std::shared_ptr<CpuBarrier> cpu_barrier;
41 std::unique_ptr<Kernel::Scheduler> scheduler; 71 std::unique_ptr<Kernel::Scheduler> scheduler;
42 72
43 bool reschedule_pending{}; 73 bool reschedule_pending{};
74 size_t core_index;
44}; 75};
45 76
46} // namespace Core 77} // namespace Core