cpu_core_manager.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <map>
  7. #include <memory>
  8. #include <thread>
  9. namespace Core {
  10. class Cpu;
  11. class CpuBarrier;
  12. class ExclusiveMonitor;
  13. class System;
  14. class CpuCoreManager {
  15. public:
  16. CpuCoreManager();
  17. CpuCoreManager(const CpuCoreManager&) = delete;
  18. CpuCoreManager(CpuCoreManager&&) = delete;
  19. ~CpuCoreManager();
  20. CpuCoreManager& operator=(const CpuCoreManager&) = delete;
  21. CpuCoreManager& operator=(CpuCoreManager&&) = delete;
  22. void Initialize(System& system);
  23. void Shutdown();
  24. Cpu& GetCore(std::size_t index);
  25. const Cpu& GetCore(std::size_t index) const;
  26. Cpu& GetCurrentCore();
  27. const Cpu& GetCurrentCore() const;
  28. ExclusiveMonitor& GetExclusiveMonitor();
  29. const ExclusiveMonitor& GetExclusiveMonitor() const;
  30. void RunLoop(bool tight_loop);
  31. void InvalidateAllInstructionCaches();
  32. private:
  33. static constexpr std::size_t NUM_CPU_CORES = 4;
  34. std::unique_ptr<ExclusiveMonitor> exclusive_monitor;
  35. std::unique_ptr<CpuBarrier> barrier;
  36. std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cores;
  37. std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> core_threads;
  38. std::size_t active_core{}; ///< Active core, only used in single thread mode
  39. /// Map of guest threads to CPU cores
  40. std::map<std::thread::id, Cpu*> thread_to_cpu;
  41. };
  42. } // namespace Core