diff options
Diffstat (limited to 'src/core/core_cpu.h')
| -rw-r--r-- | src/core/core_cpu.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h new file mode 100644 index 000000000..243f0b5e7 --- /dev/null +++ b/src/core/core_cpu.h | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <atomic> | ||
| 8 | #include <condition_variable> | ||
| 9 | #include <memory> | ||
| 10 | #include <mutex> | ||
| 11 | #include <string> | ||
| 12 | #include "common/common_types.h" | ||
| 13 | |||
| 14 | class ARM_Interface; | ||
| 15 | |||
| 16 | namespace Kernel { | ||
| 17 | class Scheduler; | ||
| 18 | } | ||
| 19 | |||
| 20 | namespace Core { | ||
| 21 | |||
| 22 | constexpr unsigned NUM_CPU_CORES{4}; | ||
| 23 | |||
| 24 | class CpuBarrier { | ||
| 25 | public: | ||
| 26 | bool IsAlive() const { | ||
| 27 | return !end; | ||
| 28 | } | ||
| 29 | |||
| 30 | void NotifyEnd(); | ||
| 31 | |||
| 32 | bool Rendezvous(); | ||
| 33 | |||
| 34 | private: | ||
| 35 | unsigned cores_waiting{NUM_CPU_CORES}; | ||
| 36 | std::mutex mutex; | ||
| 37 | std::condition_variable condition; | ||
| 38 | std::atomic<bool> end{}; | ||
| 39 | }; | ||
| 40 | |||
| 41 | class Cpu { | ||
| 42 | public: | ||
| 43 | Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index); | ||
| 44 | |||
| 45 | void RunLoop(bool tight_loop = true); | ||
| 46 | |||
| 47 | void SingleStep(); | ||
| 48 | |||
| 49 | void PrepareReschedule(); | ||
| 50 | |||
| 51 | ARM_Interface& ArmInterface() { | ||
| 52 | return *arm_interface; | ||
| 53 | } | ||
| 54 | |||
| 55 | const ARM_Interface& ArmInterface() const { | ||
| 56 | return *arm_interface; | ||
| 57 | } | ||
| 58 | |||
| 59 | const std::shared_ptr<Kernel::Scheduler>& Scheduler() const { | ||
| 60 | return scheduler; | ||
| 61 | } | ||
| 62 | |||
| 63 | bool IsMainCore() const { | ||
| 64 | return core_index == 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | private: | ||
| 68 | void Reschedule(); | ||
| 69 | |||
| 70 | std::shared_ptr<ARM_Interface> arm_interface; | ||
| 71 | std::shared_ptr<CpuBarrier> cpu_barrier; | ||
| 72 | std::shared_ptr<Kernel::Scheduler> scheduler; | ||
| 73 | |||
| 74 | bool reschedule_pending{}; | ||
| 75 | size_t core_index; | ||
| 76 | }; | ||
| 77 | |||
| 78 | } // namespace Core | ||