cpu_core_manager.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. explicit CpuCoreManager(System& system);
  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();
  23. void StartThreads();
  24. void Shutdown();
  25. Cpu& GetCore(std::size_t index);
  26. const Cpu& GetCore(std::size_t index) const;
  27. Cpu& GetCurrentCore();
  28. const Cpu& GetCurrentCore() const;
  29. ExclusiveMonitor& GetExclusiveMonitor();
  30. const ExclusiveMonitor& GetExclusiveMonitor() const;
  31. void RunLoop(bool tight_loop);
  32. void InvalidateAllInstructionCaches();
  33. private:
  34. static constexpr std::size_t NUM_CPU_CORES = 4;
  35. std::unique_ptr<ExclusiveMonitor> exclusive_monitor;
  36. std::unique_ptr<CpuBarrier> barrier;
  37. std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cores;
  38. std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> core_threads;
  39. std::size_t active_core{}; ///< Active core, only used in single thread mode
  40. /// Map of guest threads to CPU cores
  41. std::map<std::thread::id, Cpu*> thread_to_cpu;
  42. System& system;
  43. };
  44. } // namespace Core