core_cpu.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <atomic>
  6. #include <condition_variable>
  7. #include <memory>
  8. #include <mutex>
  9. #include <string>
  10. #include "common/common_types.h"
  11. class ARM_Interface;
  12. namespace Kernel {
  13. class Scheduler;
  14. }
  15. namespace Core {
  16. constexpr unsigned NUM_CPU_CORES{4};
  17. class CpuBarrier {
  18. public:
  19. bool IsAlive() const {
  20. return !end;
  21. }
  22. void NotifyEnd();
  23. bool Rendezvous();
  24. private:
  25. unsigned cores_waiting{NUM_CPU_CORES};
  26. std::mutex mutex;
  27. std::condition_variable condition;
  28. std::atomic<bool> end{};
  29. };
  30. class Cpu {
  31. public:
  32. Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index);
  33. void RunLoop(bool tight_loop = true);
  34. void SingleStep();
  35. void PrepareReschedule();
  36. ARM_Interface& ArmInterface() {
  37. return *arm_interface;
  38. }
  39. const ARM_Interface& ArmInterface() const {
  40. return *arm_interface;
  41. }
  42. const std::shared_ptr<Kernel::Scheduler>& Scheduler() const {
  43. return scheduler;
  44. }
  45. bool IsMainCore() const {
  46. return core_index == 0;
  47. }
  48. private:
  49. void Reschedule();
  50. std::shared_ptr<ARM_Interface> arm_interface;
  51. std::shared_ptr<CpuBarrier> cpu_barrier;
  52. std::shared_ptr<Kernel::Scheduler> scheduler;
  53. bool reschedule_pending{};
  54. size_t core_index;
  55. };
  56. } // namespace Core