diff options
author | bunnei <bunneidev@gmail.com> | 2018-05-11 18:59:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-11 18:59:23 +0200 |
commit | 1b5c02fc37206bbd33715d2dde6258c3f835581c (patch) | |
tree | 1c33c66e734ff55228e4293cd2720070cd467080 /src/core/core_cpu.h | |
parent | Merge pull request #439 from ogniK5377/GetTPCMasks (diff) | |
parent | core: Add several missing docstrings. (diff) | |
download | yuzu-1b5c02fc37206bbd33715d2dde6258c3f835581c.tar yuzu-1b5c02fc37206bbd33715d2dde6258c3f835581c.tar.gz yuzu-1b5c02fc37206bbd33715d2dde6258c3f835581c.tar.bz2 yuzu-1b5c02fc37206bbd33715d2dde6258c3f835581c.tar.lz yuzu-1b5c02fc37206bbd33715d2dde6258c3f835581c.tar.xz yuzu-1b5c02fc37206bbd33715d2dde6258c3f835581c.tar.zst yuzu-1b5c02fc37206bbd33715d2dde6258c3f835581c.zip |
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 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <atomic> +#include <condition_variable> +#include <memory> +#include <mutex> +#include <string> +#include "common/common_types.h" + +class ARM_Interface; + +namespace Kernel { +class Scheduler; +} + +namespace Core { + +constexpr unsigned NUM_CPU_CORES{4}; + +class CpuBarrier { +public: + bool IsAlive() const { + return !end; + } + + void NotifyEnd(); + + bool Rendezvous(); + +private: + unsigned cores_waiting{NUM_CPU_CORES}; + std::mutex mutex; + std::condition_variable condition; + std::atomic<bool> end{}; +}; + +class Cpu { +public: + Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index); + + void RunLoop(bool tight_loop = true); + + void SingleStep(); + + void PrepareReschedule(); + + ARM_Interface& ArmInterface() { + return *arm_interface; + } + + const ARM_Interface& ArmInterface() const { + return *arm_interface; + } + + const std::shared_ptr<Kernel::Scheduler>& Scheduler() const { + return scheduler; + } + + bool IsMainCore() const { + return core_index == 0; + } + +private: + void Reschedule(); + + std::shared_ptr<ARM_Interface> arm_interface; + std::shared_ptr<CpuBarrier> cpu_barrier; + std::shared_ptr<Kernel::Scheduler> scheduler; + + bool reschedule_pending{}; + size_t core_index; +}; + +} // namespace Core |